Skip to content

Instantly share code, notes, and snippets.

@capaj
Created November 20, 2016 23:56
Show Gist options
  • Save capaj/a42ff3efe5f26009e89cc6e431c28d89 to your computer and use it in GitHub Desktop.
Save capaj/a42ff3efe5f26009e89cc6e431c28d89 to your computer and use it in GitHub Desktop.
global-store
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