Comments (1)
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)
- 这主题也太黑了 哥 晃眼睛 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ripple.