项目作者: kamilglod

项目描述 :
Aurelia plugin for redux
高级语言: JavaScript
项目地址: git://github.com/kamilglod/aurelia-redux.git
创建时间: 2017-02-13T22:41:23Z
项目社区:https://github.com/kamilglod/aurelia-redux

开源协议:Other

下载


Aurelia-Redux-Immutable

Aurelia plugin for redux is auto inject state and dispatcher to view models. Additionally it keeps synced redux state in view models so it will be auto updated when change occurred.

Installation

  • using Aurelia CLI:
    • run npm install immutable redux aurelia-redux-immutable
    • add
      1. "immutable",
      2. {
      3. "name": "redux",
      4. "path": "../node_modules/redux/dist",
      5. "main": "redux"
      6. }
      7. "aurelia-redux-immutable",
      to aurelia.json

Configuration

Use this plugin as standard aurelia plugin, just pass your store instance.

  1. aurelia.use
  2. .standardConfiguration()
  3. .plugin('aurelia-redux-immutable', storeInstance);

Simple usage

  1. import connect from 'aurelia-redux-immutable';
  2. class SomeViewModel {
  3. constructor() {
  4. connect(this);
  5. // each time state change occured this.state will be updated to the newest version
  6. console.log(this.dispatch, this.state);
  7. }
  8. }

Usage with reselect

  1. import connect from 'aurelia-redux-immutable';
  2. import { username, isAuthorizedState } from 'store/user/selectors';
  3. const mapState = (state) => {
  4. return {
  5. isAuthorized: isAuthorizedState(state),
  6. username: username(state),
  7. };
  8. };
  9. class SomeViewModel {
  10. constructor() {
  11. connect(this, mapState);
  12. // each time state change occured this.state will be updated to the newest version
  13. // if substate returned by mapState will differ
  14. console.log(this.dispatch, this.state);
  15. }
  16. }

To see full example please check example-app