-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from Coding/fs-module-refactor
M 0.14.0 finish
- Loading branch information
Showing
10 changed files
with
110 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import mapEntityFactory from './mapEntity' | ||
import defaultProps from './defaultProps' | ||
import protectedObservable from './protectedObservable' | ||
|
||
export { mapEntityFactory, defaultProps } | ||
export { mapEntityFactory, defaultProps, protectedObservable } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { observable, computed } from 'mobx' | ||
|
||
/* | ||
* This decorator enforce a pattern that's widely used in this project, | ||
* | ||
* @protectedObservable _foo = 'bar' | ||
* | ||
* is a short hand for: | ||
* | ||
* @observable _foo = 'bar' | ||
* @computed | ||
* get foo () { return this._foo } | ||
* set foo (value) { return this._foo = value } | ||
* | ||
* you can specify publicKey explicitly by calling: | ||
* @protectedObservable('publicFoo') _foo = 'bar' | ||
*/ | ||
function _protectedObservableDecorator (target, privateKey, descriptor, publicKey) { | ||
if (!publicKey) publicKey = privateKey.replace(/^_/, '') | ||
|
||
const computedDescriptor = computed(target, publicKey, { | ||
get () { return this[privateKey] }, | ||
set (v) { return this[privateKey] = v }, | ||
}) | ||
|
||
Object.defineProperty(target, publicKey, computedDescriptor) | ||
|
||
return observable(target, privateKey, descriptor) | ||
} | ||
|
||
function protectedObservable (optionalPublicKey) { | ||
if (typeof optionalPublicKey === 'string') { | ||
return function protectedObservableDecorator (target, key, descriptor) { | ||
return _protectedObservableDecorator(target, key, descriptor, optionalPublicKey) | ||
} | ||
} else { | ||
return _protectedObservableDecorator.apply(null, arguments) | ||
} | ||
} | ||
export default protectedObservable |