Giter Club home page Giter Club logo

miniflux's Introduction

miniflux

Build Status

A Small Boilerplate-Free Flux(ish) Library for React Apps

JSBin

Overview

npm install --save miniflux

Examples below assume browserify. dist/ contains standalone builds if that's what you need.

Create a store with some initial state, and register any action handlers and callbacks.

var Flux = require('miniflux');

var initialState = {foo: 'bar'};
var MyStore = Flux.Store(initialState)
  .registerHandler('myAction', handleAction)
  .registerHandler('anotherAction', [foo, bar, baz])
  .registerCallback(aCallback);

function handleAction() {
  // called when miniflux dispatches `myAction`
  // `this` is the instance of miniflux.Store
}

function aCallback() {
  // called after the store handles any action
  // before `miniflux.change` is emitted.
}

Then interact with the store in your React components:

var Flux = require('miniflux');
var MyStore = require('./path/to/mystore');

var MyComponent = React.createClass({
  componentDidMount: function() {
    MyStore.on(Flux.change, this._changeListener);
  },
  anEventHandler: function() {
    Flux.Action('myAction');
  },
  _changeListener: function() {
    this.replaceState(MyStore.currentState());
  }
  // ...
});

API

miniflux.Store()

Returns a store instance.

#registerHandler(name, method)

name: string name of action to handle
method: function of array of functions that handle the action. Context is bound to the store instance being handled.

#registerCallback(method)

method: function called before each change event is emitted. Bound to the store context.

note: Action handlers and callbacks may be associated with multiple stores.

#currentState()

Returns the current value of state

#destroy()

Removes the store from the miniflux registry.

miniflux.Action(action)

Checks all stores for handlers assigned to action. If action is handled by a store, that stores callbacks (if any) are called, followed by the store emitting the miniflux.change event. Throws an error is nothing handles action.

LICENSE

MIT

miniflux's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

rubythonode

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.