ericelliott/irecord

Add updateIn or array methods to API

Open

#11 创建于 2015年6月15日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)JavaScript (9 fork)github user discovery
enhancementhelp wanted

仓库指标

Star
 (191 star)
PR 合并指标
 (PR 指标待抓取)

描述

its currently difficult to manage arrays with only a set and get method.

irecord.set('arr', ['bob','tim','terry'] );

this will give us an immutable object with an immutably list at key 'arr'. we can use the set API to get to certain indices of the array, but if we want to push, pop or splice anything new, we at best can manually set a new index or overwrite an old one.

updateIn

If we expose the updateIn method, the user could reach the array, and apply a transform method. The entirety of irecord would still work as a getter/setter. I dont see a lot of downside except that its more complex than a simple value based getter/setter.

irecordThing.updateIn( 'keyThatGetsArray', function(arr) { 
    arr.push( 'newThing' )
    return arr;
});

push, pop, splice etc

If we're very set on not exposing updateIn, then we could consider mapping some array methods that internally use updateIn. This would match the getter/setter api and OOP feeling of not using a transform method.

irecordThing.set( 'keyThatGetsAnArray' ).push( 'newThing' );

贡献者指南