All Projects → azu → Material Flux

azu / Material Flux

Licence: mit
No magic flux implementation library.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Material Flux

hermes-js
Universal action dispatcher for JavaScript apps
Stars: ✭ 15 (-80.26%)
Mutual labels:  flux, dispatch
Opencad Php
Open Source Computer Aided Dispatch System for Roleplay Communities.
Stars: ✭ 64 (-15.79%)
Mutual labels:  dispatch
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (+807.89%)
Mutual labels:  dispatch
Simple Todo With React And
📝 a simple react demo to learn flux/reflux/redux
Stars: ✭ 29 (-61.84%)
Mutual labels:  flux
Delorean
An Agnostic, Complete Flux Architecture Framework
Stars: ✭ 748 (+884.21%)
Mutual labels:  flux
Fluxxkit
Unidirectional data flow for reactive programming in iOS.
Stars: ✭ 42 (-44.74%)
Mutual labels:  flux
React Quick Tutorial
🚀 讓你用最短時間,充分體會 React 的脈絡思維
Stars: ✭ 633 (+732.89%)
Mutual labels:  flux
Flocks.js
A radically simpler alternative to Flux - opinionated React state and rendering management
Stars: ✭ 72 (-5.26%)
Mutual labels:  flux
Matplotlib Chord Diagram
plot chord diagram with matplotlib
Stars: ✭ 60 (-21.05%)
Mutual labels:  flux
Duckietown.jl
Differentiable Duckietown
Stars: ✭ 29 (-61.84%)
Mutual labels:  flux
Scalecube Services
v2.0 - ScaleCube Services provides a low latency Reactive Microservices library for serverless service registry and discovery based on gossip protocol and without single point-of-failure or bottlenecks.
Stars: ✭ 23 (-69.74%)
Mutual labels:  flux
Flux Constant
📦 Unique constants for Flux apps
Stars: ✭ 18 (-76.32%)
Mutual labels:  flux
Mill.jl
Multiple Instance Learning Library is build on top of Flux.jl aimed to prototype flexible multi-instance learning models.
Stars: ✭ 43 (-43.42%)
Mutual labels:  flux
Nylas Mail
💌 An extensible desktop mail app built on the modern web. Forks welcome!
Stars: ✭ 24,653 (+32338.16%)
Mutual labels:  flux
Starter React Flux
Generate your React PWA project with TypeScript or JavaScript
Stars: ✭ 65 (-14.47%)
Mutual labels:  flux
Little State Machine
📠 React custom hook for persist state management
Stars: ✭ 654 (+760.53%)
Mutual labels:  flux
Tanok
Elm Architecture-inspired wrapper for Rx.js+React
Stars: ✭ 22 (-71.05%)
Mutual labels:  flux
Queuer
Queuer is a queue manager, built on top of OperationQueue and Dispatch (aka GCD).
Stars: ✭ 964 (+1168.42%)
Mutual labels:  dispatch
Fleur
A fully-typed, type inference and testing friendly Flux Framework
Stars: ✭ 74 (-2.63%)
Mutual labels:  flux
Reactive Flux
Fluxish model implemented with RxJS
Stars: ✭ 71 (-6.58%)
Mutual labels:  flux

material-flux Build Status

No magic flux implementation library.

  • Less trick
    • No method swizzle, No overwrite function
    • IDE Readable API(Machine Readable API)
  • Debuggable
  • ECMAScript6 compatible
  • Class syntax

Installation

npm install material-flux

Usage

material-flux is consist of Action, Store and Context.

Flux Architecture

User action -> Action -> Context dispatch -> Store received dispatch -> Store dispatch "change" event -> View received the "change". -> update view.

flow image

  • Context provide dispatch function to Actions.
  • Context register store for dispatched event.
  • Action dispatch event.
  • Store received dispatched event with data.
  • Store dispatch "change" event when update state in the store.

Action

import {Action} from "material-flux"
// it's a like constants
export const keys = {
    // "any key" : "any value"
    "doSomething": "unique value"
};
export default class UserAction extends Action {
    doSomething(data) {
        // pass the `data` to Store's `onHandler`
        // call `onHandler(data);`
        this.dispatch(keys.doSomething, data);
    }
}

When you call action, dispatch store's handler.

Store

import {keys} from "./UserAction.js"
import {Store} from "material-flux"
export default class UserStore extends Store {
   constructor(...args) {
       super(...args);
       this.state = {
           userData: null
       };
       this.register(keys.doSomething, this.onHandler);
   }

   // data is come from Action
   onHandler(data) {
       this.setState({
           userData: data
       });
   }

   // just getter method
   getUserData() {
       return this.state.userData;
   }
}

Store#onChange(listener)

Adds a listener to the end of the listeners array for the "change" event.

  • listener is a function.

Store#removeChangeListener(listener)

Removes a "change" listener.

  • listener is a function.

Store#removeAllChangeListeners()

Removes all "change" listeners.

Store#getState()

Return state object that shallowly clone store's state.

Store#setState(object)

Update this.state and emit "change" event.

  • object is any object.

Context

How to connect Action and Store? => Create connection object. it is called Context in this context.

import UserAction from "./UserAction.js"
import UserStore from "./UserStore.js"
import {Context} from 'material-flux';
export default class UserContext extends Context {
    constructor() {
        super();
        this.userAction = new UserAction(this);
        this.userStore = new UserStore(this);
    }
}

View(Component)

How to connect to View like React? => Pass an instance of Context to React's Component.

import React from 'react';
import UserContext from './UserContext.js';
import App from './AppComponent.jsx';
var context = new UserContext();
React.render(
    React.createElement(App, { context }),
    document.getElementById('main')
);

AppComponent:

import React from 'react';
export default class AppComponent extends React.Component {
    constructor(...args) {
        super(...args);
        this.userStore = this.props.context.userStore;
        this.state = {
            userData: this.userStore.getUserData()
        };
    }

    _onChange() {
        this.setState({
            userData: this.userStore.getUserData()
        });
    }

    componentDidMount() {
        this.userStore.onChange(this._onChange.bind(this));
    }

    componentWillUnmount() {
        this.userStore.removeAllChangeListeners();
    }

    onClick(event) {
        var { context } = this.props;
        context.userAction.doSomething("clicked");
    }

    render() {
        return (
            <div onClick={this.onClick.bind(this)}>
                userData: {this.state.userData}
            </div>
        );
    }
}

Container

If you want to Container Component, use https://github.com/azu/material-flux-container

Examples

more examples.

Tests

npm test
# it run mocha & npm run test:typing.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT

Inspiration and thanks

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].