Skip to content

Commit

Permalink
[update] Rename get to pull
Browse files Browse the repository at this point in the history
  • Loading branch information
nhunzaker committed Mar 31, 2015
1 parent 2697187 commit c196e3b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ overall surface area of the app has been reduced and more opinions have
been made.

- Renamed `Microcosm::seed` to `Microcosm::push`
- Renamed `Microcosm::get` to `Microcosm::pull`
- Removed `Microcosm::has`
- Removed `Microcosm::getInitialState`. the `Store` API still provides
this function, however it is the expectation of the system that
Expand Down
2 changes: 1 addition & 1 deletion docs/cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Data Operations
+--------------+
clone - Return a new object whose prototype is the last state
commit - Assign a new state, trigger an event
get - Provided a key, return that entry in the state object
pull - Provided a key, return that entry in the state object
push - Replace state with the result of deserializing a set of data
Serialization
Expand Down
24 changes: 12 additions & 12 deletions example/src/__tests__/App-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('App', function() {
})

it ('should create a new list with the proper name', function() {
app.get(Lists)[0].should.have.property('name', name)
app.pull(Lists)[0].should.have.property('name', name)
})

})
Expand All @@ -33,11 +33,11 @@ describe('App', function() {

beforeEach(function() {
app.send(ListActions.add, { name })
app.send(ListActions.remove, app.get(Lists)[0].id)
app.send(ListActions.remove, app.pull(Lists)[0].id)
})

it ('should remove the list by id', function() {
app.get(Lists).length.should.equal(0)
app.pull(Lists).length.should.equal(0)
})

})
Expand All @@ -47,11 +47,11 @@ describe('App', function() {

beforeEach(function() {
app.send(ListActions.add, { name: 'parent' })
app.send(ItemActions.add, { name, list: app.get(Lists)[0] })
app.send(ItemActions.add, { name, list: app.pull(Lists)[0] })
})

it ('should create a new item with the proper name', function() {
app.get(Items)[0].should.have.property('name', name)
app.pull(Items)[0].should.have.property('name', name)
})

})
Expand All @@ -61,12 +61,12 @@ describe('App', function() {

beforeEach(function() {
app.send(ListActions.add, { name: 'parent' })
app.send(ItemActions.add, { name, list: app.get(Lists)[0] })
app.send(ItemActions.remove, app.get(Items)[0].id)
app.send(ItemActions.add, { name, list: app.pull(Lists)[0] })
app.send(ItemActions.remove, app.pull(Items)[0].id)
})

it ('remove the item by id', function() {
app.get(Items).length.should.equal(0)
app.pull(Items).length.should.equal(0)
})

})
Expand All @@ -76,12 +76,12 @@ describe('App', function() {

beforeEach(function() {
app.send(ListActions.add, { name: 'parent' })
app.send(ItemActions.add, { name, list: app.get(Lists)[0] })
app.send(ListActions.remove, app.get(Lists)[0].id)
app.send(ItemActions.add, { name, list: app.pull(Lists)[0] })
app.send(ListActions.remove, app.pull(Lists)[0].id)
})

it ('removes all child items', function() {
app.get(Items).length.should.equal(0)
app.pull(Items).length.should.equal(0)
})

})
Expand All @@ -94,7 +94,7 @@ describe('App', function() {
})

it ('simply updates the state with the provided parameters', function() {
app.get(Route).should.eql(params)
app.pull(Route).should.eql(params)
})

})
Expand Down
6 changes: 3 additions & 3 deletions src/Microcosm.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default class Microcosm {
this._plugins = []
}

get(key) {
return this._state[key]
pull(key) {
return key ? this._state[key] : this._state
}

prepare(fn, ...buffer) {
Expand Down Expand Up @@ -87,7 +87,7 @@ export default class Microcosm {
}

serialize() {
return remap(this._stores, store => store.serialize(this.get(store)))
return remap(this._stores, store => store.serialize(this.pull(store)))
}

deserialize(data={}) {
Expand Down
12 changes: 5 additions & 7 deletions src/__tests__/Microcosm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ describe('Microcosm', function() {
m._stores.should.have.property(DummyStore)
})

it ('gets default state for a store if it has not been assigned', function(done) {
it ('pulls default state for a store if it has not been assigned', function(done) {
let m = new Microcosm()

m.addStore(DummyStore)

m.start(function() {
m.get(DummyStore).should.equal(DummyStore.getInitialState())
m.pull(DummyStore).should.equal(DummyStore.getInitialState())
}, done)
})

Expand Down Expand Up @@ -55,15 +55,13 @@ describe('Microcosm', function() {
})
})

it ('can funnel data into stores', function() {
it ('can push data into stores', function() {
let mixture = { fiz: 'buz' }
let m = new Microcosm()

m.addStore(DummyStore)

m.funnel({ dummy: mixture })

m.get(DummyStore).should.equal(mixture)
m.push({ dummy: mixture })
m.pull(DummyStore).should.equal(mixture)
})

it ('can send sync messages to the dispatcher', function() {
Expand Down

0 comments on commit c196e3b

Please sign in to comment.