GithubHelp home page GithubHelp logo

paulcookie / riot-redux-mixin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ibloat/riot-redux-mixin

0.0 2.0 0.0 6 KB

A riot mixin connecting tags to your redux store

License: ISC License

JavaScript 100.00%

riot-redux-mixin's Introduction

riot-redux-mixin

A riot mixin to connect tags to your redux store. Memoizing your selectors is probably a good idea (see https://github.com/ibloat/riot-redux-sample)

Usage

// get your store
var store = configureStore()

// pass the store to the mixin and tell riot about it
riot.mixin('redux', riotReduxMixin(store))

and then in your tags

this.mixin('redux')

// if needed mix actions or action creators into the tag via dispatchify
var foo = require('actions/foo')
this.dispatchify({ foo })

// these are now equivalent
this.foo()
this.dispatch(foo())

// if needed subscribe in some way
this.subscribe(function(state) { return { bar: state.foo.bar } }) // this.bar will be set on update
// or use reselect to reduce the amount of update() calls
var selector = require('selectors/bar')
this.subscribe(selector) // whatever object the selector returns will be merged into the tag
// you can also pass in a callback that will be called instead of this.update
this.subscribe(selector, console.log)

API

  • dispatch(action) - what it says on the box
  • dispatchify({actions}) - this one takes your action objects or action creators and makes them available in your tag's scope to be dispatched directly (without having to wrap them in dispatch() every time). The actions parameter is an object containing the actions so by calling this.dispatchify({foo}) you then can dispatch foo via this.foo() instead of this.dispatch(foo()). This is quite handy when you want to dispatch actions from DOM events.
  • subscribe(selector, callback = this.update) - selector is a function that gets passed the current state and is expected to return an object. The object's keys will be merged into the tag's scope. For larger projects using a memoizing library like reselect is probably a good idea. That way your tag will only get updated when state relevant to your tag has changed. When not passing in a callback your tag will get updated with the new state via this.update(obj).

riot-redux-mixin's People

Contributors

ibloat avatar paulcookie avatar

Watchers

 avatar  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.