Skip to content

Instantly share code, notes, and snippets.

@dtothefp
Last active February 23, 2018 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtothefp/4c3fbcddc0cd3667be05 to your computer and use it in GitHub Desktop.
Save dtothefp/4c3fbcddc0cd3667be05 to your computer and use it in GitHub Desktop.
import { Store, toImmutable } from 'nuclear-js';
import {OPEN, CLOSE} from './modal-constants';
export const isOpenStore = Store({
getInitialState() {
return false;
},
initialize() {
// Sets isOpen to true
this.on(OPEN, (state, {id}) => {
let newState;
if(!state) {
newState = toImmutable({id: [id]});
} else if(!state.get('id').filter((i) => id === i ).size) {
newState = toImmutable({id: state.get('id').push(id)});
} else {
newState = state;
}
return newState;
});
// Reverts to initial state
this.on(CLOSE, (state, {id}) => {
state = state.toJS();
let i = state.id.indexOf(id);
state.id.splice(i, 1);
return toImmutable(state);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment