Giter Club home page Giter Club logo

Comments (4)

neonstalwart avatar neonstalwart commented on June 22, 2024

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.

Raynos avatar Raynos commented on June 22, 2024

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.

neonstalwart avatar neonstalwart commented on June 22, 2024

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.

Raynos avatar Raynos commented on June 22, 2024

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

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.