New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mobx-easy-state

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

mobx-easy-state

Mobx with minimal API

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source

mobx-easy-state

This library is just a util on top of mobx. The api is lifted from react-easy-state, which is excellent but doesn't support IE or react-native Android.

Introduction

Two rules:

  • Always wrap your components with view.
  • Always wrap your state store objects with store.

Installation

$ npm install --save mobx mobx-react mobx-easy-state

Usage

import React from "react"
import { view, store } from "mobx-easy-state"
import moment from "moment"

const timer = store({
  ticks: 0,
  id: null,
  toggle() {
    if (!this.id) {
      this.id = setInterval(() => this.ticks++, 10)
    } else {
      this.id = clearInterval(this.id)
    }
  },
  get time() {
    return moment(this.ticks * 10).format("mm:ss")
  },
  get fraction() {
    return moment(this.ticks * 10).format("SS")
  },
  get label() {
    return this.id ? "Stop" : "Start"
  },
})

export default view(() => (
  <div>
    <p>{timer.time}<small>{timer.fraction}</small></p>
    <button onClick={timer.toggle}>{timer.label}</button>
  </div>
))

How it works

Under the hood view is just an observer and store does the following:

  • Turns key/value pairs into observables.
  • Turns getters into computed properties.
  • Decorates methods with action.bound.

All normal mobx gotchas apply.

FAQs

Package last updated on 27 May 2018

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