Giter VIP home page Giter VIP logo

mobx-localstorage's People

Contributors

aihornmac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mobx-localstorage's Issues

localStorage.getItem() returns NULL for all keys - broken in v1.1.1 and above

import localStorageMobx from "mobx-localstorage"

console.log(localStorageMobx.getItem("foo") // null -- incorrect
console.log(localStorage.getItem("foo") // bar -- correct

For some reason, all values returned by mobx-localstorage are null but using the normal localstorage returns the correct value. Seems to have broken in v1.1.1, because it doesn't work in 1.1.1 or 1.1.2, but does work in 1.1.0.

Cannot use with { enforceActions: "always" } - "Since strict-mode is enabled, changing observed observable values outside actions is not allowed."

The issue is that when MobX is configured to always enforce actions, this library does not respect the pattern that all observable properties can only be modified with a function decorated as an action.

The main issue is in the constructor in the call super.set() and super.delete():

constructor() {
    super(undefined, referenceEnhancer, 'LocalStorage')
    const len = localStorage.length
    for (let i = 0; i < len; i++) {
      const key = localStorage.key(i)!
      const value = parseValue(localStorage.getItem(key))
      super.set(key, value)
    }
    localStorage.on('change', (key, value) => {
      if (typeof value === 'string') {
        super.set(key, parseValue(value))
      } else {
        super.delete(key)
      }
    })
  }

Also, the class functions for setting / removing keys should probably also be decorated as actions to be safe.

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.