Heavily inspired by react-side-effect.
Features
- Light-weight: 500 bytes gzipped
- Simple: Just a component
- Works just as well with isomorphic apps
Install
$ npm install --save side-effect
Example
It gathers current props across the whole tree before passing them to side effect. For example, this allows you to create <body-style :set-style>
component like this:
<!-- root component --><body-style :set-style="{backgroundColor: 'red'}"> <some-component></some-component></side-effect> <!-- some-component --><body-style :set-style="{backgroundColor: 'yellow'}"> <input @input="updateColor" /></side-effect>
Create a side-effect component named BodyStyle
for mutating body style from different level of nesting with innermost winning:
const BodyStyle = name: 'body-style' { if !this$slotsdefault return return this$slotsdefault0 } { const style = {} for const vm of vms Object return style} { for const key in style documentbodystylekey = stylekey } reduceInstancesToState handleStateChangeOnClientBodyStyle
Now, it's ready to go: https://side-effect.surge.sh
Server-side Usage
The API is exactly the same as react-side-effect, call rewind()
after rendering.
VueComponent
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D