GithubHelp home page GithubHelp logo

angular2-redux-bindings's Introduction

angular2 redux binding

Bind redux store and actions creators to angular2 components using annotations.

How to use:

Add to your packages:

    npm install angular2-redux-binding --save

call the initStore() before angular bootstrap:

    import {initStore} from 'angular2-redux-bindings'

    initStore(store)
    // bootstrap angular

bind state values to your component properties with @MapState:

  import {mapState} from 'angular2-redux-bindings'

  @Component({
    template: '<p>{{ value }}</p>'
  })

  class Component {

    @MapState('value')
    private value;
  }

you can bind a deeply nested value up to three levels :

  import {mapState} from 'angular2-redux-bindings'

  @Component({
      template: '<h2>{{ title }}</h2>'
    })

  class Component {

    @MapState('app.list.title')
    private title;

  }

if the value is deeply nested, use a function instead:

  import {mapState} from 'angular2-redux-bindings'

  @Component({
      template: `
            <h2>{{ title }}</h2>
            <p>{{ value }} </p>
            `
  })

  class Component {

    @MapState()
    mapStateToThis(state){
      return {
        title: state.app.list.title,
        value: state.app.list.item.value
      }
    }
  }

Bind an action creator to a component property with @BindActions:

  import {bindActions}   from 'angular2-redux-bindings'
  import {actionCreator} from 'your-acrions'

  @Component({
      template: `<button (click)='action()'>click</h2>`
   })

  class Component {

    @BindActions(actionCreator)
    private action;
  }

Bind multiple action creators:

  import {bindActions} from 'angular2-redux-bindings'
  import * as actions  from 'your-acrions'

  @Component({
     template: `<button (click)='actions.action()'>click</h2>`
  })


  class Component {

    @BindActions(actions)
    private actions;
  }

The module is under development, but the API won't change so you can use it in your project if you like.

contribution:

PR's are welcome! the module does't required any compilation. just clone it. to run tests (in watch mode) run;

  npm test

angular2-redux-bindings's People

Contributors

nirkaufman avatar shirihaim avatar

Watchers

 avatar

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.