Coder Social home page Coder Social logo

promy's Introduction

PromyStore

Escrito por Matias Trujillo Olivares

Allows you to manage asynchronous states within an application by leveraging the potential of promises and Redux ideas on Flux. This tool perfectly complements PromyCycle

First steps

First I want to remember that you create PromyStore by understanding that all events generated within an application are mostly ASYNCHRONIZED (Server calls, client events, animations and time intervals). For this, PromyStore offers a simple interface, composed of 4 interaction methods to manage this asynchrony.

  • action : Allows you to define store actions
  • middleware : Define middleware that runs when launching an action
  • dispatch : Allows to issue shares to the store
  • subscribe : Subscribe to store changes
  • unsubscribe : Allows you to unsubscribe from store changes
  • child : It allows you to generate a child that issues the father changes of his own state.

Implementing PromyStore Example 1

This example demonstrates a simple storage based on a counter.

var store = new PromyStore(0);

store.middleware((store,action,next)=>{
  console.log(action)
  return next(store,action);
})

store.action({
  ADD(state,{value}){
    return state + value;
  },
  RES(state,{value}){
    return state - value;
  }
})

store.subscribe((state)=>{
  document.querySelector('#view-total').textContent = state;
})

Explaining Example 1

Middleware

This method pertaining to the store allows to define a middleware for the same store, this one receives a function, that to the sold by the store will give 3 parameters

  • @param {Object} - It's store status
  • @param {Object} - The action issued by the dispatcher
  • @param {Function} - Function that allows to continue the process, this returns a promise

Action

They allow to manage a state change based on a specific type of action, if by default the action is not defined, the action will be issued ** default **

Child

It allows to generate properties belonging to the store, but these are in turn sub instances of PromyStore, similar to how it operates combinerReduce in redux, but this is asynchronous

Subscribe

It allows to subscribe to the states of the store, this receives a function that when executed will receive 2 parameters store state and actin modifying the state.

promy's People

Contributors

uppercod avatar

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.