Skip to content

Instantly share code, notes, and snippets.

@butchler
Last active October 18, 2016 12:35
Show Gist options
  • Save butchler/20e34ea36dff8a11d86d5664c55a5ffa to your computer and use it in GitHub Desktop.
Save butchler/20e34ea36dff8a11d86d5664c55a5ffa to your computer and use it in GitHub Desktop.
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