diff --git a/docs/createStore.md b/docs/createStore.md index 547e67a5..2d602635 100644 --- a/docs/createStore.md +++ b/docs/createStore.md @@ -31,21 +31,6 @@ Available configuration options: `getState` receives the current state and returns a copy of it. You can override this function to provide your own implementation. -#### stateKey - -`stateKey` is a string that controls where state should be defined at this particular store's level. For example: - -```js -class TodoStore { - static config = { - stateKey: 'state' - } - constructor() { - this.state = { todos: {} } - } -} -``` - #### onSerialize `onSerialize` is also called before the store's state is serialized. You may optionally return an object, which will be used directly as the snapshot data for the store. If you do not return anything, the default, [`MyStore#getState()`](stores.md#storegetstate) is used for the snapshot data. See the [serialization](serialization.md) for an example. diff --git a/docs/index.md b/docs/index.md index a756254a..465197e8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -65,31 +65,6 @@ This controls how store data is serialized in snapshots. By default alt uses `JS This controls how store data is deserialized from snapshot/bootstrap data. By default alt uses `JSON.parse`, but you can provide your own function to deserialize data. -#### stateKey - -`stateKey` is a string that controls where state should be defined at the store level. For example: - -```js -var alt = new Alt({ - stateKey: 'cherry' -}); - -class MyStore { - constructor() { - // state now goes in this.cherry - this.cherry = { - a: 1, - b: 2, - c: 3 - }; - - // instance properties declared below do not go into state - this.isPrivate = 'yes' - this.yay = true - } -} -``` - #### stateTransforms This is an array of functions you can provide which will be executed every time `createStore` or `createUnsavedStore` is ran. It will iterate through the array applying each function to your store. This can be useful if you wish to perform any pre-processing or transformations to your store before it's created. diff --git a/src/alt/store/index.js b/src/alt/store/index.js index 2f0bdc44..a1337c55 100644 --- a/src/alt/store/index.js +++ b/src/alt/store/index.js @@ -125,7 +125,7 @@ export function createStoreFromClass(alt, StoreModel, key, ...argsForClass) { new AltStore( alt, store, - store[alt.config.stateKey] || store[config.stateKey] || null, + typeof store.state === 'object' ? store.state : null, StoreModel ), utils.getInternalMethods(StoreModel), diff --git a/src/utils/ImmutableUtil.js b/src/utils/ImmutableUtil.js index 69ec75ce..e17a8388 100644 --- a/src/utils/ImmutableUtil.js +++ b/src/utils/ImmutableUtil.js @@ -2,8 +2,6 @@ import Immutable from 'immutable' function immutable(StoreModel) { StoreModel.config = { - stateKey: 'state', - setState(currentState, nextState) { this.state = nextState return this.state diff --git a/test/custom-state-key-test.js b/test/custom-state-key-test.js deleted file mode 100644 index 541c25d7..00000000 --- a/test/custom-state-key-test.js +++ /dev/null @@ -1,26 +0,0 @@ -import { assert } from 'chai' -import Alt from '../dist/alt-with-runtime' - -const alt = new Alt({ - stateKey: 'state' -}) - -class Store { - static displayName: 'CustomStateKeyStore' - - constructor() { - this.foo = 1 - this.state = { yes: 2 } - } -} - -const store = alt.createStore(Store) - -export default { - 'Custom State Key': { - 'setting a custom key for declaring state'() { - assert.isUndefined(store.getState().foo, 'foo is private') - assert.isDefined(store.getState().yes, 'yes is part of state') - }, - } -} diff --git a/test/decorators-test.js b/test/decorators-test.js index 491176c3..c83154df 100644 --- a/test/decorators-test.js +++ b/test/decorators-test.js @@ -18,7 +18,6 @@ export default { 'decorate store creation with args'() { @createStore(alt, 1, 2, 3) class StoreArgs { - static config = { stateKey: 'state' } constructor(one, two, three) { this.state = { one, two, three } }