Last active
October 18, 2016 12:35
-
-
Save butchler/20e34ea36dff8a11d86d5664c55a5ffa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class MyStore extends Record({ a: 0, b: List() }) { | |
constructor(values) { | |
super(values); | |
const mySelector = createSelector( | |
[(record) => record.a, (record, arg) => arg], | |
(a, arg) => a + arg | |
); | |
Object.defineProperty(this, 'mySelector', | |
Object.getOwnPropertyDescriptor(values, 'mySelector') || | |
{ | |
value: function (...args) { | |
return mySelector(this, ...args); | |
}, | |
} | |
); | |
const myComputed = createSelector( | |
[(record) => record.a], | |
(a) => a * a | |
); | |
Object.defineProperty(this, 'myComputed', | |
Object.getOwnPropertyDescriptor(values, 'myComputed') || | |
{ | |
get: function () { | |
return myComputed(this); | |
}, | |
} | |
); | |
copyProperty(values, this, 'mySelector', () => { | |
const mySelector = createSelector( | |
[(record) => record.a, (record, arg) => arg], | |
(a, arg) => a + arg | |
); | |
return { | |
value: function (...args) { | |
return mySelector(this, ...args); | |
}, | |
}; | |
}); | |
copyGetters(values, this, { | |
myComputed: selector( | |
['a'], | |
(a) => a * a, | |
), | |
}); | |
copySelectors(values, this, { | |
mySelector: selector( | |
['a', (record, arg) => arg], | |
(a, arg) => a + arg, | |
customEqualityChecker | |
)), | |
}); | |
copyProperties(values, this, { | |
mySelector: () => selector(createSelector( | |
[(record, arg) => record.a, (record, arg) => arg], | |
(a, arg) => a + arg | |
)), | |
myComputed: () => getter(createComputed( | |
['a'], | |
(a) => a * a | |
)), | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment