Open dashed opened 9 years ago
The only time this is good
// deliberate bad practice
struct.cursor('foo').update(function() {
return Immutable.List.of(1, 2);
});
is during bootstrap when you're loading your models before React.render(...)
and before listeners are registered:
// enable debug mode
if ('production' !== process.env.NODE_ENV) {
immstruct.debug();
}
const struct = immstruct({foo: [1, 2]});
// load model from database, xhr, etc.
// this is done before any listeners are subscribed.
struct.cursor('foo').update(function() {
return Immutable.List.of(1, 2);
});
function render() {
React.render(<Component cursor={struct.cursor()}) />);
// value propagation check is enabled after the first render
struct.on('swap', render);
}
render();
// deliberate bad practice
struct.cursor('foo').update(function() {
return Immutable.List.of(1, 2);
});
I was thinking on this some more: https://github.com/omniscientjs/omniscient/issues/104#issuecomment-109815813
Rather than doing this naive check in
shouldComponentUpdate
, this may be done during development as an indicator that it should never occur. This can warn users that they're not really using the immutable library effectively.API sketch: