Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove warning when returning a string from .serialize #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion docs/docs/api/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ Static Methods

### serialize(state)

If you use `Flux.serialize`, Flummox will try to call the static method `serialize` on all your stores. Flummox will pass the state object of the store to the method and expects a String
If you use `Flux.serialize`, Flummox will try to call the static method `serialize` on all your stores. Flummox will pass the state object of the store to the method and leave it to you to return any custom serialization. Whatever you return will be bundled into an overall store object with store names as keys and whatever the various `serialize` methods return as values. This entire object is `stringified` and output in `Flux.serialize` method.

If you don't have any reason for custom serialization, you can just `return state` and it will be stringified by `Flux.serialize`.

### deserialize(state)

Expand Down
16 changes: 2 additions & 14 deletions src/Flux.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,9 @@ export default class Flux extends EventEmitter {

if (typeof serialize !== 'function') continue;

const serializedStoreState = serialize(store.state);
const storeState = serialize(store.state);

if (typeof serializedStoreState !== 'string') {
const className = store.constructor.name;

if (process.env.NODE_ENV !== 'production') {
console.warn(
`The store with key '${key}' was not serialized because the static `
+ `method \`${className}.serialize()\` returned a non-string with type `
+ `'${typeof serializedStoreState}'.`
);
}
}

stateTree[key] = serializedStoreState;
stateTree[key] = storeState;

if (typeof store.constructor.deserialize !== 'function') {
const className = store.constructor.name;
Expand Down
16 changes: 0 additions & 16 deletions src/__tests__/Flux-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,22 +449,6 @@ describe('Flux', () => {
});
});

it('warns if any store classes .serialize() returns a non-string', () => {
const flux = new Flux();
const warn = sinon.spy(console, 'warn');

flux.createStore('foo', createSerializableStore({}));
flux.serialize();

expect(warn.firstCall.args[0]).to.equal(
'The store with key \'foo\' was not serialized because the static '
+ 'method `SerializableStore.serialize()` returned a non-string with '
+ 'type \'object\'.'
);

console.warn.restore();
});

it('warns and skips stores whose classes do not implement .deserialize()', () => {
const flux = new Flux();
const warn = sinon.spy(console, 'warn');
Expand Down