1.0.9 • Published 9 years ago

fluxd v1.0.9

Weekly downloads
7
License
ISC
Repository
-
Last release
9 years ago

Flux'd

A work in progress ES6 Flux framework.

Examples

// ./actions/UserActions.js

import flux from 'fluxd';

class UserActions {
  constructor() {
    this.generateActions('createUser', 'updateUser', 'destroyUser');
  }
}

export default flux.createActions(UserActions);
// ./stores/UserStore.js

import {List} from 'immutable';
import UserActions from '../actions/UserActions';

const PAYLOAD = new Symbol('users payload');

class UserStore {
  constructor() {
    this.bindActions(UserActions);
    this[PAYLOAD] = List();
  }

  onCreateUser(user) {
    this[PAYLOAD] = this[PAYLOAD].concat([data]);
  }

  onUpdateUser(user) {
    var payload = this[PAYLOAD];
    var index = payload.findIndex(user => user.get('id') === user.id);
    this[PAYLOAD] = payload.setIn([index], user);
  }

  onDestroyUser(userId) {
    var payload = this[PAYLOAD];
    var index = payload.findIndex(user => user.id === userId);
    this[PAYLOAD] = payload.delete(index);
  }

  static getActive() {
    return this.getState().filter(user => user.active);
  }
}

export default flux.createStore(UserStore);
1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago