reactivez
Universal reactive storage for data. Inspired by VueJS.
Last updated 3 years ago by zolbooo .
MIT · Original npm · Tarball · package.json
$ cnpm install reactivez 
SYNC missed versions from official npm registry.

reactivez

npm version npm total downloads Universal reactive storage for data. Inspired by VueJS

Getting started

You can reactive storage in any appliation: React, Node.JS, etc.

Example:

import ReactDOM from "react-dom";
import React, { Component } from "react";

import ReactiveStorage from "reactivez";

let reactiveStorage = new ReactiveStorage({
  messages: []
});
class App extends Component {
  constructor(props) {
    super(props);
    this.state = { messages: [] };
  }
  componentWillMount() {
    this.handle = reactiveStorage.subscribe("messages", messages =>
      this.setState({ messages })
    );
  }
  componentWillUnmount() {
    reactiveStorage.deleteSubscribe(this.handle); // Delete subscribe in order to prevent memory leak
  }
  render() {
    return (
      <div>
        {this.state.messages.map(message => (
          <p>{message}</p>
        ))}
      </div>
    );
  }
}
ReactDOM.render(<App />, document.getElementById("root"));

Now you can set reactiveStorage.data.messages and state of App component will be updated.

Reference

new ReactiveStorage(data)

Create new reactive storage with specific initial state.

ReactiveStorage.subscribe(field, callback)

Subscribe on updates of ReactiveStorage.data[field]. If it's setter is called, callback is called with new value passed to it. Returns handle of subscribe.

ReactiveStorage.deleteSubscribe(handle)

Delete subscribe with specific handle. Used to prevent memory leaks. Handle is value returned on subscribe call.

Current Tags

  • 1.0.0-2                                ...           latest (3 years ago)

3 Versions

  • 1.0.0-2                                ...           3 years ago
  • 1.0.0-1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (8)
Dependents (0)
None

Copyright 2014 - 2021 © npmmirror.com |