New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

flux-reducer

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flux-reducer

The flux-like data flow library.

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Flux-Reducer

The flux-like data flow for JavaScript apps.

It helps you write applications that behave consistently, run in different environments (client, server and native), have the good encapsulation and decouple with each other.

Installation

To install the flux-reducerwith npm:

npm install --save flux-reducer

Tutorials

Now let's talk with the todo-list as a example.

First, we need create the Todo reducer that can receive the message relative to 'Todo'.

import { Reducer } from 'flux-reducer';

class TodoReducer extends Reducer({
  name: '',
  detail: '',
  isCompleted: false,
}) {
  changeName(name) {
    this.trigger(this.set('name', name));
  }
};

The UI can send the 'changeName' to TodoReducer to change the Todo name. The trigger will broadcast the new reducer to all subscribers.

Then, we need create Todos reducer that can respond to Todo collection related actions.

import { ArrayReducer } from 'flux-reducer';

class TodosReducer extends ArrayReducer {
  constructor() {
    super(...arguments);
    this.monitorAllValues();
  }

  addTodo(todo) {
    this.trigger(this.push(new TodoReducer(todo)));
  }
}

We need invoke TodosReducer's' addTodo method to add the new Todo instance.

Now, we can subscribe to TodosReducer to get the new state.

let todosReducer = new TodosReducer;
todosReducer.subscribe((newReducer) => {
  console.log('the todos have changed.');
});

todosReducer.addTodo({
  name: 'new todo',
});

Invoke this code segment, the log information will show in the terminal.

Keywords

FAQs

Package last updated on 01 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc