Giter Club home page Giter Club logo

cache-store's Introduction

cache-store

数据缓存,支持 React 组件之间数据共享。

USAGE

var store = require('cache-store');

class Foo extends React.Component {
  constructor(props) {
    super(props);
    store.set('name', 'Foo'); // 触发 store 中的 name 值更新
  }
}

class Bar extends React.Component {
  constructor(props) {
    super(props);
    this.state = {barName: ''};

    // 每次 store 中的 name 改变了, Bar 中的 barName 也会跟着改变
    store.map('name', 'barName', this);
  }

  componentWillUnmount() {
    store.unmap('fooName', 'barName'); // 取消绑定
  }

  render() {
    return <div>{this.state.barName}</div>
  }
}

API

local

对 localStorage 对象的一个封装,支持任意类型的 value,同时支持设置过期时间

local.set(key, val, [expiredAfterSeconds])

local.get(key)

local.del(key)

local.empty()

set(key, val, [saveToLocal])

get(key, [getFromLocalIfNotExists])

del(key, [removeFromLocal])

empty([removeFromLocal])

on(key, callback)

off(key, [callback])

map(key, reactStateKey, reactComponent, [filter])

unmap(key, [reactStateKey, [reactComponent]])

saveToLocal(key)

getFromLocal(key)

removeFromLocal(key)

cache-store's People

Contributors

qiu8310 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.