Comments (4)
alternatively
var Event = require('geval/event');
module.exports = Observable;
function Observable(value) {
var event = new Event();
value = value === undefined ? null : value;
observable.set = function (v) {
value = v;
event.broadcast(v);
};
return observable;
function observable(listener) {
if (!listener) {
return value;
}
return event.listen(listener);
}
}
from mercury.
geval
and observ
represents different data structures.
geval
represents an immutable series of discrete events. Once you have a geval
instance all you can do is listen to events.
observ
represents a mutable value over time. Once you have an observ
instance you can ask it for its current value at any point, you may mutate it and you may listen for changes to the value.
This distinction is based on FRP literature.
For example note the computed()
function in observ
. It does not make sense to create a computed event (because the answer to "whats the current value" of a series of discrete events is not defined).
In the future both geval
and observ
may have other higher order functions that only apply on themself.
from mercury.
ok, but what about my alternative implementation that uses geval
to implement observ
? the current semantics are unchanged with this but it has the benefit of removing duplicated code? events and behaviors are still distinct but we leverage code reuse.
from mercury.
@neonstalwart We could use geval in observ.
However that saves a few lines of code and makes observ harder to read. observ
currently is a zero dependencies module. I think it's easier to reason about as is on it's own.
from mercury.
Related Issues (20)
- live component reloading HOT 6
- Mercury not exporting virtual-hyperscript SVG HOT 2
- Immutable props
- question: how to detect if a widget has been unmounted HOT 2
- Communication between child components
- Why static render methods? HOT 3
- Using vdom-to-html doesn't work (returns empty string) HOT 6
- Redux + mercury example? HOT 10
- lock down wiki?
- syntax of h HOT 2
- npm install fails HOT 1
- 14.1.0 break all VNode input rendering HOT 8
- newb question HOT 4
- Docs/Introduction: Simple Cycle example missing
- Synchronize tagged version and comment in mercury.js
- Rendering subitems of different types HOT 4
- What is the right way to pass data to click event handlers? HOT 1
- Get the previous version of state var HOT 3
- Splitting components out to their own render loop? HOT 2
- How to attach state to renderer? HOT 10
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 mercury.