# virtex-component

> Component rendering middleware for virtex

Latest version **0.5.5** (published 2017-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install virtex-component
pnpm add virtex-component
yarn add virtex-component
bun add virtex-component
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.5 |
| Published | 2017-07-19 |
| First published | 2015-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 13 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | ashaffer88 |

## Links

- npm: https://www.npmjs.com/package/virtex-component
- Repository: https://github.com/ashaffer/virtex-component
- Homepage: https://github.com/ashaffer/virtex-component#readme
- Issues: https://github.com/ashaffer/virtex-component/issues
- npm.io page: https://npm.io/package/virtex-component

## Dependencies (13)

- [redux](https://npm.io/package/redux.md) ^3.6.0
- [virtex](https://npm.io/package/virtex.md) ^0.3.8
- [@f/reduce](https://npm.io/package/@f/reduce.md) ^1.0.0
- [redux-flo](https://npm.io/package/redux-flo.md) latest
- [@f/defaults](https://npm.io/package/@f/defaults.md) ^1.0.1
- [@f/identity](https://npm.io/package/@f/identity.md) ^1.1.1
- [redux-falsy](https://npm.io/package/redux-falsy.md) ^1.0.0
- [redux-multi](https://npm.io/package/redux-multi.md) ^0.1.12
- [@f/equal-obj](https://npm.io/package/@f/equal-obj.md) ^1.2.1
- [@f/equal-array](https://npm.io/package/@f/equal-array.md) ^1.2.2
- [redux-ephemeral](https://npm.io/package/redux-ephemeral.md) ^0.3.7
- [tcomb-validation](https://npm.io/package/tcomb-validation.md) ^3.3.0
- [@f/curry-transparently](https://npm.io/package/@f/curry-transparently.md) ^1.0.0

## Recent versions

- 0.5.5 (latest) — 2017-07-19
- 0.5.4 — 2017-05-24
- 0.5.3 — 2017-04-05
- 0.5.2 — 2016-12-05
- 0.5.1 — 2016-11-18
- 0.5.0 — 2016-11-09
- 0.4.3 — 2016-04-09
- 0.4.2 — 2016-03-10
- 0.4.1 — 2016-03-07
- 0.4.0 — 2016-03-07
- 0.3.5 — 2016-03-03
- 0.3.4 — 2016-03-03
- 0.3.3 — 2016-02-25
- 0.3.2 — 2016-02-25
- 0.3.1 — 2016-01-28
- … 13 more at https://npm.io/package/virtex-component/versions

## README

# virtex-component

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

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:

```javascript
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](https://github.com/ashaffer/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](https://github.com/ashaffer/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.

```javascript
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.

```javascript
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 &copy; 2015, Weo.io &lt;info@weo.io&gt;

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.

---
_Source: https://npm.io/package/virtex-component · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
