Giter Site home page Giter Site logo

uxter / fluxter Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 2.0 93 KB

:rocket: Simple container of unidirectional data flow.

License: ISC License

JavaScript 100.00%
flux store unidirectional-data-flow unidirectional action middleware reducer state subscribe es6

fluxter's Introduction

view on npm npm module downloads Build Status Coverage Status Dependency Status Join the chat at https://gitter.im/fluxter

Fluxter is a simple container of unidirectional data flow.

Fluxter data flow

Install

$ npm install --save fluxter

Classes

Fluxter

Functions

addReducer(stateKey, reducer)

Add reducer to store

addMiddleware(middleware)

Add middleware to store

addAction(actionName, action)

Add action to store

dispatch(actionName, ...args)

Dispatch action to store

subscribe(handler)

Add handler

next(actionData)

Call next middleware or done

Fluxter

Kind: global class
Access: public

new Fluxter()

Class Fluxter

Example

let store = new Fluxter({
    user: {
        logged: false,
        name: null,
        token: null
    }
});

addReducer(stateKey, reducer)

Add reducer to store

Kind: global function

Param Type Description
stateKey String A state field
reducer function A pure function

Example

store.addReducer('user', (state = {}, actionName, actionData) => {
    if (actionName === 'login') {
        return {
            ...state,
            logged: actionData.logged,
            name: actionData.name,
            token: actionData.token
        };
    }
    return state;
});

addMiddleware(middleware)

Add middleware to store

Kind: global function

Param Type Description
middleware function A middleware function

Example

store.addMiddleware('user', (store, actionName, actionData, next) => {
    if (actionName === 'login') {
        SomeRepository.check(actionData).then(data => next({
            ...data,
            ...actionData
        }));
    } else {
        next(actionData);
    }
});

addAction(actionName, action)

Add action to store

Kind: global function

Param Type Description
actionName String An action name
action function An action creator function

Example

store.addAction('login', (name, password) => ({
    name,
    password
}));

dispatch(actionName, ...args)

Dispatch action to store

Kind: global function

Param Type Description
actionName String An action name
...args * Arguments that take action

Example

store.dispatch('login', 'example-name', 'example-password');

subscribe(handler)

Add handler

Kind: global function

Param Type Description
handler function Change state handler

Example

store.subscribe(store => view.setState(store.state));

next(actionData)

Call next middleware or done

Kind: global function

Param Type Description
actionData * An action data

Example

Online game SeaWars. Example of using Fluxter.

๐Ÿ’ฅ Try it out ๐Ÿ’ฅ

Note on Patches/Pull Requests

  1. Fork the project.
  2. Make your feature addition or bug fix.
  3. Send me a pull request.

ยฉ 2017 Vasily Shilov

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.