Code Monkey home page Code Monkey logo

lenstore's Introduction

LenStore (WIP)

External state implemented with lenses !

TODO

  • pouvoir composer plusieurs stores entre eux. genre :
friendsStore = createStore([
  userStore
])

userStore = createStore({
  name: 'aze',
  age: 22,
  friends: friendsStore
})
  • implementation d'un map et d'un contramap qui s'applique a chaque fois que le store (ou le focus) est utilisé

  • implementation de lens spécifique, genre RefLens qui prend une reférence, mais qui peut être vu avec view

  • un middleware qui s'execute au moment du createLensesFromObject qui permet de choisir la lens en fonction d'une predicate genre :

    const store = createStore()
    
    store.addLens(atomLens, (v) => !!v.$atom)
    store.addLens(refLens, (v) => !!v.$ref)
    
    const initialState = {
      herosById: {
        1: { name: 'Iron Man' },
        2: { name: 'Hulk' },
        3: { name: 'Invisible Man' }
      },
      visible: [
        { $ref: { object: "herosById", key: 1 } },
        { $ref: { object: "herosById", key: 2 } }
      ]
    }
    
    store.init(initialState)

New Target API :

Use just like a regular object :

const state = {
  user: {
    username: 'toto',
    age: 22
  },
  bookmark: ['The Knick', 'Breaking Bad', 'True Detective']
}


// createStore :: InitialState -> Observable State

const store = createStore(state)

store.subscribe(state => {
  console.log(state)
})


const { L, view, over, set } = store
view(L.user.username)
over(L.user.username, username => `${username}!!`)
set(L.user.username, 'Henry')

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.