GithubHelp home page GithubHelp logo

yamiteru / stoic Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 749 KB

Tiny, fast and simple TypeScript functional reactive library.

License: MIT License

TypeScript 98.81% JavaScript 1.19%
reactive reactive-programming functional-reactive-programming reactive-streams event-driven typescript

stoic's Introduction

Stoic

Tiny, fast and simple TypeScript functional reactive library.

Concepts

Observable

Something that emits values over time to which you can listen to. It starts its life once it's created and ends either by error or end.

There are 3 types of events to which you can listen to:

  1. onNext listens to new values
  2. onError listens to errors
  3. onEnd listens to the end of the observable

There are 2 core types of observables:

  1. stream doesn't remember the latest value
  2. value does remember the latest value

Value mapping

Every observable has some sort of input and output value. Their shapes can be completely different and for that there is a map.

It accepts input value and outputs either output value or undefined. Undefined is used to stop the propagation of the output value to subscribers.

Derivation

Each observable type has its derived version. Derived observables derive their input value from an array of output values of other observables.

Derived observables are updated internally by an array of observables so there is no next method for manually passing input values into them.


API

Observables

Stream

const simpleLogger$ = stream<[type: string, message: any]>(null, {
  next: ([type, message]) => console.log(type.toUpperCase(), message)
});

derivedStream

const squidStats$ = derivedStream([players$, reward$], ([players, reward]) => [
  `${players.length} 염`,
  `₩ ${reward.toWon()}`
]);

value

const price$ = value<number>(0, isPositive);
const count$ = value<number>(0, isPositive);

derivedValue

const sum$ = derivedValue([price$, count$], ([price, count]) => price * count);

Future

  • Tests
  • Benchmarks
  • pipe (once it's possible to define types that would support an unlimited number of functions)
  • React hooks

Have a beautiful day 🍀

stoic's People

Contributors

dependabot[bot] avatar yamiteru avatar

Stargazers

 avatar

Watchers

 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.