virtex-component
Component rendering middleware for virtex
Last updated 3 years ago by ashaffer88 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install virtex-component 
SYNC missed versions from official npm registry.

virtex-component

js-standard-style

Component rendering middleware for virtex

Installation

$ npm install virtex-component

Usage

Install it in your middleware stack like this:

applyMiddleware(component(), dom(document), ...others)

Then export components like this:

function onCreate ({props}) {
  return fetchSomeData()
}

function render ({props, children}) {
  return (
    <ul style={{color: props.color}}>
      children.map(child => <li>{child}</li>)
    </ul>
  )
}

export default {
  onCreate,
  render
}

Model

Components are passed an object that contains (at least) 3 things:

  • props - An object of the properties passed in by the calling component
  • children - An array of the children specified by the calling component
  • path - The numerical (e.g. 0.1.3) path in the component tree. This will be used to store your local state if you don't specify a key (by virtex-local).
  • key - The key specified by your parent in props (optional).

These are all of the things that virtex-component will put into your model. But other effect, such as virtex-local processors may add additional properties.

Lifecycle hooks

All lifecycle hooks receive model (and possibly prevModel) and may return an action. That action will be dispatched back into redux - this and only this is how your lifecyle hooks may effect the outside world.

  • onCreate - When the component is created. Receives model.
  • onUpdate - When the model changes. Receives prev and next models.
  • onRemove - When the component is removed. Receives model.

shouldUpdate

By default, your component will only update if a shallow equality check fails for your children or prev/next props. However, by exporting a custom shouldUpdate function, you can control this yourself.

getProps

Use this to transform props before they're passed into any of your component's other methods. It receives only props, and should return a new props object. E.g.

function getProps (props) {
  return {
    ...props,
    timeout: props.timeout || 0
  }
}

Component map

If you pass an object to virtex-component when you install it, it will maintain a map for you of components to paths. E.g.

const map = {}
applyMiddleware(component(map), ...)

Here, map will contain a mapping between components and paths. This can be useful for implementing fast sub-tree re-rendering.

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.5.5                                ...           latest (3 years ago)

28 Versions

  • 0.5.5                                ...           3 years ago
  • 0.5.4                                ...           4 years ago
  • 0.5.3                                ...           4 years ago
  • 0.5.2                                ...           4 years ago
  • 0.5.1                                ...           4 years ago
  • 0.5.0                                ...           4 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.5                                ...           5 years ago
  • 0.3.4                                ...           5 years ago
  • 0.3.3                                ...           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.11                                ...           5 years ago
  • 0.1.8                                ...           5 years ago
  • 0.1.10                                ...           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.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 1
Dependencies (13)
Dev Dependencies (4)

Copyright 2014 - 2016 © taobao.org |