ericelliott/irecord

Add updateIn or array methods to API

Open

#11 opened on Jun 15, 2015

View on GitHub
 (1 comment) (0 reactions) (0 assignees)JavaScript (9 forks)github user discovery
enhancementhelp wanted

Repository metrics

Stars
 (191 stars)
PR merge metrics
 (PR metrics pending)

Description

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' );

Contributor guide