1.0.9 • Published 10 years ago

fluxd v1.0.9

Weekly downloads
7
License
ISC
Repository
-
Last release
10 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

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago