Coder Social home page Coder Social logo

most-cree8's Introduction

Most-Cree8

An alternative to most-create

This is a very short condensed implementation of the "create" stream/observable creation pattern for Mostjs. It does not follow most of the normal Most decorum, as I still don't understand the traditional (but undocumented) ceremonies and class hierarchies of most/core, but it should be reasonably complete and speedy.

Unlike @most/create, this implementation will by-default immediately, synchronously call the creation function. Added values and errors will be ignored however until the the observable becomes observed, but it can significantly reduce code complexity by passing these methods immediately (alike how new Promise(...) does).

API

var add
var stream= new MostCree8(function(_add, end, error){
	add= _add
	add("ignored") // this will be ignored since no one is subscribed to this stream while it is being created
})
add("ignored") // this will be ignored since the stream is still not subscribed to
stream.forEach(console.log)
add(1) //=> 1

Alternatively one can request the creation function not be called until it is observed:

var add
var stream= new MostCree8( function( _add, end, error){
	add= _add
	add( 1) //=> 1
	process.nextTick(_ => add(3)) //=> 3
}, true) // true here says to defer running the function until there is an observer
add && add( "ignored") || console.log( "not created yet") //=> not created yet, as add has not been set/create function has not been called
stream.forEach( console.log)
add( 2) //=> 2

most-cree8's People

Contributors

rektide avatar

Watchers

 avatar James Cloos avatar  avatar

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.