immutable-short-string-notation
v2.1.2
Published
Allows you to set paths directly in strings instead of passing arrays
Downloads
13
Readme
immutable-short-string-notation
Allows you to set paths directly in strings instead of passing arrays
How to use
The requirement must appear in the app before other immutable actions (a good idea would be to place in the root of the app if uncertain)
require('immutable-short-string-notation');
Somewhere else in the application you may use the string syntax
state.setIn('a.b.c.d.e', 42);
state.getIn('a.b.c.d.e'); // 42
// All other ways still work
state.setIn('a.b.c.d.e'.split('.'), 42);
state.setIn(['a', 'b', 'c', 'd', 'e'], 42);
state.getIn('a.b.c.d.e'); // still 42
Why ?
because writing state.getIn(['node1', 'node23', 'node67'])
could be shorter
and state.getIn('node1.node23.node67'.split('.'))
feel wrong when it's been repeaded a tousand times
so let's just remove the split as anyway we are sure we want to pass an array here
Installation (available on npm)
npm install --save immutable-short-string-notation
or
yarn add immutable-short-string-notation --save