itree
(alpha)
simple tree operations on immutable.js "trees"
many interesting things can be modelled as trees. for example, consider the following layout for a movie banner
<view> <image src='poster.jpg'> <text style=fontSize: 10 fontFamily: 'helvetica'> Movie Title </text> <text className='description'> Where dreams are made </text> </image></view>
this can also be represented as the following
let tree = immutable;
itree gives you the primitives to manipulate this structure, while leaving the original unchanged.
; // you can point to any node in the tree with a path like so -// [0] -> <view><image...</view>// [0, 0] -> <image.... </image>// [0, 0, 1] -> <text className='description'...</text> // get node at path // <image.... </image> // add a node at path// <view>// <image src='thumb.jpg'/>// <image src='poster.jpg'>// ...// </image>// </view> // remove a node from path// <view></view> // move a node from one path to another// <view>// <text style={{fontSize...</text>// <image src='poster.jpg'>// <text className='description'...</text>// </image>// </view> // change the type of a node// <xyz>// <image src='poster.jpg'>// ...// </image>// </xyz> // set the props of a node// <view>// <image src='poster.jpg', a={1}>// ...// </image>// </view>
tests
npm test
further work
- more functions (up, down, diff, patch, etc)
- demos
- jsx helpers to generate trees