Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

sonicjs

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sonicjs

Reactive async operations

latest
Source
npmnpm
Version
0.5.2
Version published
Weekly downloads
2
-80%
Maintainers
2
Weekly downloads
 
Created
Source

Sonic

npm version Build Status Coverage Status Join the chat at https://gitter.im/joostverdoorn/sonic

Installing

npm install sonicjs

Examples

Map and print a state, asynchronously.

import { State } from 'sonic.ts';
const log = console.log.bind(console);

var state = State.fromArray([1,2,3]);
var mapped = State.map(state, value => {
  // Do something async
  return Promise.resolve(value * 2);
});

State.toArray(mapped).then(log); // [2,4,6]

Convert iterables over space and time.

import { AsyncIterator, State, Observable } from 'sonic.ts'
const log = console.log.bind(console);

var it = AsyncIterator.fromObject({a: 1, b: 2});
var state = State.fromEntries(it);
var observable = Observable.fromIterator(it);

AsyncIterator.toArray(it).then(log); // [['a', 1], ['b', 2]]
AsyncIterator.toArray(State.entries(state)).then(log); // [['a', 1], ['b', 2]]
AsyncIterator.toArray(Observable.toIterator(observable)).then(log); // [['a', 1], ['b', 2]]

Create reactive stores

import { AsyncIterator, State, Store, Observable, Patch } from 'sonic.ts'
var log = console.log.bind(console);

var state = State.fromObject({a: 3, b: 4, c: 5});
var subject = Subject.create();

var store = Store.create(state, subject);
var scanned = Store.scan(store, (x, y) => x + y, 0);

State.toObject(scanned.state)
  .then(log) // { a: 3, b: 7, c: 12 }
  .then(() => {
    return store.dispatcher.onNext(Patch.set(6, 'b')).then(() => {
      return State.toObject(scanned.state).then(log); // { a: 3, b: 9, c: 14 }
    });
  });

scanned.dispatcher.subscribe({
  onNext: log // { range: [{prev: "b"}, {next: "b"}], added: State({b: 9}) }
});

Keywords

reactive

FAQs

Package last updated on 16 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts