🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis
Socket
Book a DemoInstallSign in
Socket

cache-store

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-store

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

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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)

Keywords

react

FAQs

Package last updated on 28 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts