Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-contextual",
"version": "5.0.1",
"version": "5.0.2",
"description": "store and hoc patterns for react 16s new context model",
"main": "dist/react-contextual",
"module": "dist/react-contextual.es",
Expand Down
3 changes: 2 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ProviderContext, {
export function createStore(state, id = uuid()) {
const result = {
id,
initialState: { ...state },
state,
subscriptions: new Set(),
context: createNamedContext(id),
Expand Down Expand Up @@ -60,7 +61,7 @@ export class Provider extends React.PureComponent {
if (!store)
this.store.context = id ? createNamedContext(id) : ProviderContext
// Overwrite the functions in store.state to update the state of this Provider
const actions = getStateUpdateFunctions(this.store.state)
const actions = getStateUpdateFunctions(this.store.initialState)
Object.assign(
this.store.state,
Object.keys(actions).reduce(
Expand Down
18 changes: 18 additions & 0 deletions tests/__snapshots__/store.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ exports[`external store 1`] = `
"destroy": [Function],
"getState": [Function],
"id": "externalTest",
"initialState": Object {
"async": [Function],
"count": 0,
"functional": [Function],
"simple": [Function],
},
"state": Object {
"async": [Function],
"count": 0,
Expand Down Expand Up @@ -182,6 +188,12 @@ exports[`external store 2`] = `
"destroy": [Function],
"getState": [Function],
"id": "externalTest",
"initialState": Object {
"async": [Function],
"count": 0,
"functional": [Function],
"simple": [Function],
},
"state": Object {
"async": [Function],
"count": 2,
Expand Down Expand Up @@ -234,6 +246,9 @@ exports[`external store, setState 1`] = `
"destroy": [Function],
"getState": [Function],
"id": "externalTest2",
"initialState": Object {
"count": 0,
},
"state": Object {
"count": 0,
"setState": [Function],
Expand Down Expand Up @@ -280,6 +295,9 @@ exports[`external store, setState 2`] = `
"destroy": [Function],
"getState": [Function],
"id": "externalTest2",
"initialState": Object {
"count": 0,
},
"state": Object {
"count": 1,
"setState": [Function],
Expand Down
18 changes: 18 additions & 0 deletions tests/__snapshots__/subscribe.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,9 @@ exports[`subscribe(store) 1`] = `
"destroy": [Function],
"getState": [Function],
"id": "testStore",
"initialState": Object {
"message": "success!",
},
"state": Object {
"message": "success!",
"setState": [Function],
Expand Down Expand Up @@ -946,6 +949,9 @@ exports[`subscribe(store) 1`] = `
"destroy": [Function],
"getState": [Function],
"id": "testStore",
"initialState": Object {
"message": "success!",
},
"state": Object {
"message": "success!",
"setState": [Function],
Expand Down Expand Up @@ -988,6 +994,9 @@ exports[`subscribe(store, "state") 1`] = `
"destroy": [Function],
"getState": [Function],
"id": "testStore",
"initialState": Object {
"message": "success!",
},
"state": Object {
"message": "success!",
"setState": [Function],
Expand Down Expand Up @@ -1030,6 +1039,9 @@ exports[`subscribe(store, "state") 1`] = `
"destroy": [Function],
"getState": [Function],
"id": "testStore",
"initialState": Object {
"message": "success!",
},
"state": Object {
"message": "success!",
"setState": [Function],
Expand Down Expand Up @@ -1076,6 +1088,9 @@ exports[`subscribe(store, context => context) 1`] = `
"destroy": [Function],
"getState": [Function],
"id": "testStore",
"initialState": Object {
"message": "success!",
},
"state": Object {
"message": "success!",
"setState": [Function],
Expand Down Expand Up @@ -1114,6 +1129,9 @@ exports[`subscribe(store, context => context) 1`] = `
"destroy": [Function],
"getState": [Function],
"id": "testStore",
"initialState": Object {
"message": "success!",
},
"state": Object {
"message": "success!",
"setState": [Function],
Expand Down