Created
November 20, 2016 23:56
-
-
Save capaj/a42ff3efe5f26009e89cc6e431c28d89 to your computer and use it in GitHub Desktop.
global-store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {action, toJS} from 'mobx' | |
import storedObservable from './util/stored-observable' | |
const state = storedObservable('contact-list-state', { | |
contacts: [], | |
selectedId: null, | |
selectedType: null, | |
get selected () { | |
const propName = this.selectedType + 's' | |
const collection = this[propName] | |
if (collection) { | |
return collection[this.selectedId] | |
} | |
return null | |
}, | |
@action selectNothing (type, obj) { | |
state.selectedType = null | |
state.selectedId = null | |
}, | |
@action select (type, obj) { | |
state.selectedType = type | |
state.selectedId = obj.id | |
}, | |
tags: [{ | |
name: 'random-user', | |
id: 0 | |
}], | |
pendingRequestCount: 0 | |
}) | |
export default state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment