You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

sonicjs

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sonicjs

Reactive async operations

Source
npmnpm
Version
0.4.0
Version published
Maintainers
1
Created
Source

Sonic

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

Installing

npm install sonic.ts

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 14 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