npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

immutable-reflux

v1.0.2

Published

A uni-directional (flux-like) data flow archicture using immutablity and observables. This project is rename to 'angular-reflux'. Checkout https://www.npmjs.com/package/angular-reflux

Downloads

2

Readme

immutable-reflux

THIS PROJECT IS RENAMED TO angular-reflux!

About

Flux is an architecture for unidirectional data flow. By forcing the data to flow in a single direction, Flux makes it easy to reason how data-changes will affect the application depending on what actions have been issued. The components themselves may only update application-wide data by executing an action to avoid double maintenance nightmares.

Inspired by redux and refluxjs, I wrote this library to help you implement a unidirectional data flow in 5 simple steps.

Install

npm install angular-reflux

5 Simple Steps

1. Define State

To get the best out of TypeScript, declare an interface that defines the structure of the application-state.

export interface Todo {
    id?: string;
    title?: string;
    completed?: boolean;
}

export interface State {
    todos?: Todo[];
    selectedTodo?: Todo;
}

2. Define Action

Define actions as classes with the necessary arguments passed on to the constructor. This way we will benefit from the type checking; never again we will miss-spell an action, miss a required parameter or pass a wrong parameter. Remember to extend the action from Action class. This makes your action listenable and dispatch-able.

import { Action } from 'angular-reflux';

export class AddTodoAction extends Action {
    constructor(public todo: Todo) { super(); }
}

3. Create Store & Bind Action

Use @BindAction decorator to bind a reducer function with an Action. The second parameter to the reducer function (addTodo) is an action (of type AddTodoAction); @BindAction uses this information to bind the correct action. Also remember to extend this class from Store.

import { Injectable } from '@angular/core';
import { BindAction, Store } from 'angular-reflux';
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';

@Injectable()
export class TodoStore extends Store {

    @BindAction()
    addTodo(state: State, action: AddTodoAction): Observable<State> {
        return Observable.create((observer: Observer<State>) => {
            observer.next({ todos: state.todos.concat([action.todo]) });
            observer.complete();
        });
    }
}

Did you notice @Injectable()? Well, stores are injectable modules and uses Angular's dependency injection to instantiate. So take care of adding store to providers and to inject into app.component. Read Organizing Stores to understand more.

4. Dispatch Action

No singleton dispatcher! Instead this module lets every action act as dispatcher by itself. One less dependency to define, inject and maintain.

new AddTodoAction({ id: 'sd2wde', title: 'Sample task' }).dispatch();

5. Consume Data

Use @BindData decorator and a selector function (parameter to the decorator) to get updates from application state. The property gets updated only when the value, returned by the selector function, changes from previous state to the current state. Additionally, just like a map function, you could map the data to another value as you choose.

We may, at times need to derive additional properties from the data, sometimes using complex calculations. Therefore @BindData can be used with functions as well.

import { BindData } from 'angular-reflux';

@Component({
    ....
})
export class TodoListComponent {

    // mapping a direct value from state
    @BindData((state: State) => state.todos)
    protected todos: Todo[];

    // mapping a different value from state
    @BindData((state: State) => state.todos && state.todos.length > 0)
    protected hasTodos: boolean;

    // works with functions to allow complex calculations
    @BindData((state: State) => state.todos)
    protected todosDidChange(todos: Todo[]) {
        // your calculations
    }

}

Sample Code

Sample code is right here. You can clone my repo to get started with angular2 project integrated with this module.

git clone https://github.com/rintoj/angular-reflux-starter

Hope this module is helpful to you. Please make sure to checkout my other projects and articles. Enjoy coding!

Contributing

Contributions are very welcome! Just send a pull request. Feel free to contact me or checkout my GitHub page.

Author

Rinto Jose (rintoj)

Follow me: GitHub | Facebook | Twitter | Google+ | Youtube

Versions

Check CHANGELOG

License

The MIT License (MIT)

Copyright (c) 2016 Rinto Jose (rintoj)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.