Giter Club home page Giter Club logo

Comments (1)

NoMoreDeps avatar NoMoreDeps commented on July 29, 2024

HI,

In fact updateCounter will return a method, that can be used in several ways :

const update = updateCounter();

// Then you can update the state from inside the method by using a handler

// apply all pending modification to the ripple
// updateCounter(handler: (ripple) => void ) => void
updateCounter(ripple => {
  ripple.count++;
});

// cancel pending modifications
// update(handler: (ripple) => "restore") => void
update(ripple => "restore");

// reset the ripple to its initial state
// update(handler: (ripple) => "reset") => void
update(ripple => "reset");

// replace the ripple with a new value. Does not replace the initial state
// update(handler: (ripple) => typeof ripple) => void
update(ripple => {
  return {
    count: 0,
  };
});

So when the code do a this.counter it returns the method that can be used to update.
Why it use a method to get the method ?

Just because it create at the same time a proxy state dedicated to this call.
Without this, it may modify a shared state if you import twice into 2 components that try a update at the same time.

I will update the documentation to rename maybe variables to make it less confusing.
Thanks for the feedback, you are right it is ambigous.

To make it easier in the TodoService exemple I directly propose to get it that way :

class TodoService {
  constructor(protected update = updateTasks()) { }
  ...
}

from ripple.

Related Issues (2)

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.