1

I'm considering introducing Immutable JS in an existing React project. The project is littered with deeply nested references, wrapped with the selectn utility.

For example:

// returns order.id or undefined if product or order or id are undefined
if(selectn('product.order.id',this.state)) {
  //...
}

Is there an Immutable JS API method to check a deeply nested structure, and return either the requested property or undefined?

1 Answer 1

3

Here's an example.

var t = Immutable.fromJS({a: { aa: { aaa: 'thing' } } });

I want a.aa.aaa.

t.getIn(['a','aa','aaa']);
// returns "thing"

What if I try to get a.aa.bbb?

t.getIn(['a', 'aa', 'bbb']);
// Returns undefined.

Here's the API for getIn(): getIn() API.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.