npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

soboku-observable

v0.2.2

Published

template to make library by typescript

Downloads

11

Readme

Build Status codecov gzip size

soboku-observable

This is javascript package for observable by soboku.

import { interval } from "soboku-observable"
import { state, gate, editer, trigger, ntrigger } from "soboku"


// -----------------------------------------
// Prepere countdown timer
// -----------------------------------------

function getTimerMessage(isRunning: boolean) {
    return isRunning ? "Start!" : "Done!";
}

const _count = state(3),
      decCount = () => _count.next(_count.s() - 1),
      _isEnd = editer((x: number) => x === 0, [_count]),
      isEnd = trigger(_isEnd);
      isRunning = ntrigger(_isEnd),
      count = gate(isRunning, _count),
      timer = interval(1000),
      timerMessage = editer(getTimerMessage, [timer.input]);
      
count.report(console.log);
timerMessage.report(console.log);
timer.output.report(decCount);
isEnd.report(end => timer.input.next(!end));


// -----------------------------------------
// Start countdown timer
// -----------------------------------------

timer.input.next(true);

// Start!
// 2
// 1
// Done!

API

interval(ms: Atom<number>): ISObservable<State<boolean>, number>

import { interval } from "soboku"

function showLocaleTime(now: number): void {
    console.log(new Date(now).toLocaleTimeString());
}

const timer = interval(1000);
interval.output.report(showLocaleTime);

timer.input.next(true);
// ...1s later
// 21:44:58
// 21:44:59
// ... forever

timeout(ms: Atom<number>): ISObservable<State<boolean>, number>

import { timeout } from "soboku"

function done() {
    console.log("done");
}

const timer1 = timeout(1000);
const timer2 = timeout(500);
timer1.output.report(done);
// .5sec later. Restart timer1
timer2.output.report(() => timer1.input.next(true));

timer1.input.next(true);
timer2.input.next(true);

// console 1.5sec later
// done

sequenceEqual<T>(sequence: T[] | ISArray<T>, compareFn?: (x: T, y: T) => boolean): ISObservalbe<Reporter<T>, true>

import { sequenceEqual } from "soboku"

const isOKinputed = sequenceEqual(["O", "K"]);
sequenceEqual.output.report(console.log);

sequenceEqual.input.next("N");
sequenceEqual.input.next("O");
sequenceEqual.input.next("K");
// console
// true

Class

SObservable<I, O, T extends Reporter<I>>

This is abstract class.

member
  • readonly input: T
  • readonly error: Reporter<Error>
  • readonly output: Reporter<O>
  • readonly reset: Reporter<true>
constructer
  • constructer(input: T);
methods
  • protected abstract onInput(val: I): void;
  • protected abstract onReset(): void;