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

simplify store configuration #34

Closed
Ma27 opened this issue Sep 25, 2016 · 2 comments
Closed

simplify store configuration #34

Ma27 opened this issue Sep 25, 2016 · 2 comments

Comments

@Ma27
Copy link
Contributor

Ma27 commented Sep 25, 2016

Description of the issue

the current store configuration is quite powerful, but quite verbose, too and when having a more complex store which should subscribe multiple events and contains a complex state tree, it's better to make the configuration more intuitive.

Proposal

Instead we could create a subscription API which creates the object internally:

import { subscribe, store } from 'sententiaregum-flux-container';
import { ACTION } from '../constants/Foo';
import handleFoo from './handlers/handleFoo';

export default store({
  [ACTION]: subscribe([/* params */], [/* dependencies */], subscribe.chain()(handleFoo))
});

This would make everything much more readable.

It could be also possible to chain multiple handlers:

import { subscribe, store } from 'sententiaregum-flux-container';
import { ACTION } from '../constants/Foo';
import handleFoo from './handlers/handleFoo';
import handleBar from './handlers/handleBar';

export default store({
  [ACTION]: subscribe([/* params */], [/* dependencies */], subscribe.chain()(handleFoo)(handleBar))
});

And when the state needs to be copied, no function needs to be composed and the argument can be omitted:

import { subscribe, store } from 'sententiaregum-flux-container';
import { ACTION } from '../constants/Foo';

export default store({
  [ACTION]: subscribe([/* params */], [/* dependencies */])
});

New feature: modify state sections

State might be composed of multiple recursive sections:

{
  section: {
    /* values */
  }
}

Now the implementation might look like this:

import { subscribe, store } from 'sententiaregum-flux-container';
import { ACTION } from '../constants/Foo';

export default store({
  [ACTION]: subscribe([/* params */], [/* dependencies */], subscribe.chain()('section'))
});

Then it would gather all the params defined in the first array and merge them into the section.

New feature: old state in callbacks

All handlers should be able to access to old state easily.
To solve this, one last argument should be added to each handler:

src/stores/handlers/handleFoo.js

export default (param1, param2, oldState) => {
  // ...
};

This argument is always the last one and can be omitted, so no BC break here.

@Ma27 Ma27 added this to the 2.1.0 milestone Sep 25, 2016
@Ma27 Ma27 self-assigned this Sep 25, 2016
@Ma27
Copy link
Contributor Author

Ma27 commented Sep 26, 2016

The current approach to obtain single parameters that are extracted from the dispatcher payload by the connect.js isn't a good approach, so we should deprecate it.

Instead we should communicate with objects in order to simplify moving in handlers.
All legacy handlers should still receive support if they don't use this new feature.

The handler should instead look like this:

src/stores/handlers/handleFoo.js

export default ({ param1, param2 }, oldState) => {
  // ...
};

Furthermore it would simplify a lot of things as we can simply pass around objects (the old params is not needed anymore, if param1 is absent for instance, the ES6 engine will throw an exception on its own, so the whole legacy code can be deprecated to speed up the state handling)

@benbieler
Copy link
Member

@Ma27 fine.

@Ma27 Ma27 closed this as completed in 6792546 Oct 3, 2016
Ma27 added a commit that referenced this issue Oct 3, 2016
some parts of the tool growed, so a perf measurement tool has been introduced (mocha-perf-reporter) where a max ms time can be asserted to investigate how long certain operations take

added `publish` to single callback handlers and avoid re-creation of these handlers to speedup actions in long-running apps (SPAs)

resolves #35
references #34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants