virtex-local
A local state middleware for virtex components
Last updated 4 years ago by ashaffer88 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install virtex-local 
SYNC missed versions from official npm registry.

virtex-local

js-standard-style

A local state middleware for virtex components

Installation

$ npm install virtex-local

Usage

First, you need to install it in your redux middleware stack before virtex-component. E.g.

applyMiddleware(local('app'), component, dom(document), ...others)

The 'app' string passed to virtex-local tells it where in your global state atom your component state tree will be mounted. In this case, state.app is where it will live. In order for this to work, you will also need to mount redux-ephemeral into your reducer at the same key, like this:

import {mount} from 'virtex-local'

export default mount('app', reducer)

Local state

When using virtex-local, your components will receive three extra things in their model:

  • local - Wraps actions that you want to direct to your local reducer.
  • state - Your components local state.

Example

import element from 'virtex-element'

function render ({local, state}) {
  return (
    <input type='text' onChange={local(setText)} />
    <span>
      The text in your input is {state.text}
    </span>
  )
}

const SET_TEXT = 'SET_TEXT'

function setText (e) {
  const text = e.currentTarget.value

  return {
    type: SET_TEXT,
    payload: text
  }
}

function reducer (state, action) {
  switch (action.type) {
    case SET_TEXT:
      return {
        ...state,
        text: action.payload
      }
  }

  return state
}

export default {
  render,
  reducer
}

Dirty map

There is a second argument you may pass to the virtex-local middleware when you install it, dirty. If you pass this argument, virtex-local will maintain a map of the dirty state of your components. This can be useful for implementing partial subtree re-rendering optimizations. E.g.

const dirty = {}
applyMiddleware(local('app', dirty), ...)

function update (state) {
  Object.keys(dirty).forEach(key => rerenderSubtree(key)))
}

License

The MIT License

Copyright © 2015, Weo.io <info@weo.io>

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.

Current Tags

  • 0.4.11                                ...           latest (4 years ago)

34 Versions

  • 0.4.11                                ...           4 years ago
  • 0.4.10                                ...           5 years ago
  • 0.4.9                                ...           5 years ago
  • 0.4.8                                ...           5 years ago
  • 0.4.7                                ...           5 years ago
  • 0.4.6                                ...           5 years ago
  • 0.4.5                                ...           5 years ago
  • 0.4.4                                ...           5 years ago
  • 0.4.3                                ...           5 years ago
  • 0.4.2                                ...           5 years ago
  • 0.4.1                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
  • 0.3.6                                ...           5 years ago
  • 0.3.5                                ...           5 years ago
  • 0.3.4                                ...           5 years ago
  • 0.3.2                                ...           5 years ago
  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.14                                ...           5 years ago
  • 0.1.13                                ...           5 years ago
  • 0.1.12                                ...           5 years ago
  • 0.1.11                                ...           5 years ago
  • 0.1.10                                ...           5 years ago
  • 0.1.9                                ...           5 years ago
  • 0.1.8                                ...           5 years ago
  • 0.1.7                                ...           5 years ago
  • 0.1.6                                ...           5 years ago
  • 0.1.5                                ...           5 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (5)
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |