Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to use immutable-js map as store, but can't #143

Open
Termina1 opened this issue Apr 8, 2015 · 8 comments
Open

Want to use immutable-js map as store, but can't #143

Termina1 opened this issue Apr 8, 2015 · 8 comments
Labels

Comments

@Termina1
Copy link

Termina1 commented Apr 8, 2015

This is the line, where Map becomes broken https://github.com/acdlite/flummox/blob/master/src/addons/reactComponentMethods.js#L75.

And it seems, I can't anyhow configure this behaviour?

@acdlite
Copy link
Owner

acdlite commented Apr 8, 2015

Yeah, we need to replace assign() with this.constructor.assignState().

@SimonDegraeve
Copy link

+1

3 similar comments
@rn0
Copy link

rn0 commented Apr 20, 2015

+1

@athibaud
Copy link

+1

@babsonmatt
Copy link

+1

@boopathi
Copy link

any update on this ?

@chrisvariety
Copy link

In case you all didn't know, right now you can easily use Map within a store as seen on the docs sample app: https://github.com/acdlite/flummox/blob/master/docs/src/shared/stores/DocStore.js#L12

@boopathi
Copy link

I think most of the solution is already here 😃 https://github.com/acdlite/flummox-immutable-store

Looks like setState internally calls constructor.assignState, and you can simply override that to match how your Immutable object would change (/ merge).

import {Record} from 'immutable';
class MyStore extends Store {
  constructor() {
    const StateRecord = Record({ ...stateObj });
    // Set your immutable state here
    this.state = new StateRecord();
  }
  // define how your newState affects your oldState and return merged state
  static assignState(oldState, newState) {
    if (oldState === undefined || oldState === null) {
      const StateRecord = newState.constructor;
      oldState = new StateRecord();
    }
    return oldState.merge(oldState, newState);
  }
  handler() {
    // and you can just use,
    this.setState( this.state.set('prop', 'value') );
  }
}

I think, you can do that to Immutable.Map in a similar way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants