Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

geval vs observ #1

Closed
neonstalwart opened this issue Apr 3, 2014 · 4 comments
Closed

geval vs observ #1

neonstalwart opened this issue Apr 3, 2014 · 4 comments

Comments

@neonstalwart
Copy link
Collaborator

don't geval and observ do roughly the same thing (a very minor difference)? is it redundant to include both? maybe observ is sufficient for everything?

var observ = require('observ');

module.exports = Event;

function Event() {
    var value = observ();

    return { broadcast: value.set.bind(value), listen: value };
}
@neonstalwart
Copy link
Collaborator Author

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);
    }
}

@Raynos
Copy link
Owner

Raynos commented Apr 3, 2014

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.

@neonstalwart
Copy link
Collaborator Author

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.

@Raynos
Copy link
Owner

Raynos commented Apr 3, 2014

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants