symbolic-link
v1.0.1
Published
Make the property links to other target like the symbolic link.
Downloads
5
Maintainers
Readme
symbolic-link
Make the property links to other target like the symbolic link and it works well in mobx.
Installation
npm install symbolic-link
# or use yarn
yarn add symbolic-link
Usage
Simple Case
const { symbolicLink } = require('symbolic-link')
const obj = {}
const dest = { name: 'foo' }
const rm = symbolicLink(obj, 'name', dest, 'foo')
obj.name === 'foo'
obj.name = 'bar'
dest.name = 'bar'
rm()
obj.name === undefined
dest.name === 'bar'
Use in mobx
const { observable } = require('mobx')
const { defineSymbolic } = require('symbolic-link')
class Src {
@observable name
}
class Combine {
@observable obj = {
name: 'objName'
}
@observable src = defineSymbolic(new Src(), {
name: [this.obj, 'name']
})
srcX = define(new Src(), {
name: [this.obj, 'name']
})
}
const comb = new Combine()
comb.src.name === comb.obj.name
comb.srcX.name === comb.obj.name
API
symbolicLink
Parameters
srcTarget
{any}srcPropName
{String|Symbol|Number}destTarget
{any}destPropName
{String|Symbol|Number}descriptor
{object}
Examples
const obj = {}
const dest = { name: 'foo' }
const rm = symbolicLink(obj, 'name', dest, 'foo')
obj.name === 'foo'
obj.name = 'bar'
dest.name = 'bar'
rm()
obj.name === undefined
dest.name === 'bar'
Returns any dispose {Function}
symbolicTarget
Parameters
target
{any}config
{{name: [destTarget, destPropName, descriptor]}}
Examples
const obj = {}
const dest = { name: 'foo' }
const rm = symbolicTarget(obj, {
name: [dest, 'name']
})
obj.name === 'foo'
obj.name = 'bar'
dest.name === 'bar'
rm()
obj.name === undefined
dest.name === 'bar'
Returns any dispose {Function}
defineSymbolic
Parameters
target
{any}config
{{name: [destTarget, destPropName, descriptor]}}
Returns any target {any}
Contributing
- Fork it!
- Create your new branch:
git checkout -b feature-new
orgit checkout -b fix-which-bug
- Start your magic work now
- Make sure npm test passes
- Commit your changes:
git commit -am 'feat: some description (close #123)'
orgit commit -am 'fix: some description (fix #123)'
- Push to the branch:
git push
- Submit a pull request :)
Authors
This library is written and maintained by imcuttle, [email protected].
License
MIT - imcuttle 🐟