Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fromscratch/store

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fromscratch/store

The simplest store

  • 1.0.0-beta.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

@fromscratch/store

yarn add @fromscratch/store

Usage

Example with react

import React, { Componnet } from "react";
import Store from "@fromscratch/store";

const store = new Store();

export default class App extends Component {
  componentDidMount() {
    this.unsubscribe = store.subscibe("someValue", this.handleUpdate);
  }

  componentWillUnmount() {
    this.unsubscribe();
  }

  handleUpdate = data => {
    this.setState({ data });
  };

  deleteItem = index => () => {
    const currentValue = store.get("someValue", []);
    store.set("someValue", [
      ...currentValue.slice(0, index),
      ...currentValue.slice(index + 1)
    ]);
  };

  deleteAll = () => {
    store.delete("someValue");
  };

  render() {
    const { data } = this.state;
    return (
      <>
        <button onClick={this.deleteAll}>Remove all</button>
        <ul>
          {data.someList.map((item, index) => (
            <li>
              {item.label} <button onClick={this.deleteItem(index)}>x</button>
            </li>
          ))}
        </ul>
      </>
    );
  }
}

API

class Store {
  get: (key: string, defaultValue?: any) => any;
  set: (key: string, value: any) => void;
  delete: (key: string) => void;
  subscribe: (key: string, fn: (value: any) => void) => () => void;
}

FAQs

Package last updated on 10 Jan 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc