Skip to content

Commit

Permalink
Returning state from updateState (async, so it's a promise)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorengreenfield committed Oct 22, 2018
1 parent aa9dbec commit 25804ae
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -204,7 +204,7 @@ var localEvents = new eventEmitter()
Then just use `localEvents` as you would `geb`

#### State management
- `updateState` - update the global state object. You can choose to do shallow or deep merging. If you want to you can achieve Redux style updates by using `geb`. Calling updateState will cause the state object to be updated and then re-rendered.
- `updateState` - update the global state object. You can choose to do shallow or deep merging. If you want to you can achieve Redux style updates by using `geb`. Calling updateState will cause the state object to be updated and then re-rendered. Returns a promise that resolves the global state object.
- `rerender` - The global state is passed into the root component and is mutable, if you want to make deep changes within a component by mutating the state directly without using updateState, you can do so, followed by `rerender()`. By comparison, updateState merges/mutates the state and then runs rerender for you.

```js
Expand Down
8 changes: 7 additions & 1 deletion halfcab.mjs
Expand Up @@ -244,7 +244,7 @@ function updateState (updateObject, options) {
}

if (options && options.rerender === false) {
return
return Promise.resolve(state)
}

debounce(stateUpdated)
Expand All @@ -257,6 +257,12 @@ function updateState (updateObject, options) {
console.log(state)
console.log(' ')
}

return new Promise(resolve => {
nextTick(() => {
resolve(state)
})
})
}

function emptySSRVideos (c) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "halfcab",
"version": "10.1.1",
"version": "10.2.0",
"description": "A simple universal JavaScript framework focused on making use of es2015 template strings to build components.",
"main": "halfcab.mjs",
"module": "halfcab.mjs",
Expand Down

0 comments on commit 25804ae

Please sign in to comment.