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

rombok

v0.12.0

Published

RxJs utils

Downloads

27

Readme

rombok

Rombok is a library that like Lombok in java, offers less verbose solutions for common rxjs frontend use cases.

Getting started

`npm i rombok`

Api reference

AsyncProcess

AsyncProcess is a wrapper around an asynchronous observable, that includes data$, inProgress$ and error$ stream with which the lifecycle of an async process can be described.

import { AsyncProcess } from 'rombok';

const asyncProcess = new AsyncProcess(endpoint => fromFetch('https://url/' + endpoint));

$button.onclick = () => asyncProcess.execute('todos').subscribe({
    next: () => {/** some declarative logic */},
    error: () => {/** some declarative error handling  */},
});

asyncProcess.data$.subscribe(data => /** display data */);
asyncProcess.inProgress$.subscribe(isLoading => /** show/hide loader */);
asyncProcess.error$.subscribe(errorOrNull => /** show/hide error state */);

AsyncProcess.share

AsyncProcess.share is same as AsyncProcess.execute but the returned observable is shared preventing duplicated api calls.

import { AsyncProcess } from 'rombok';

const asyncProcess = new AsyncProcess(
    endpoint => fromFetch('https://url/' + endpoint));

const shared$ = asyncProcess.share('todos')

shared$.subscribe(data => /** display data in one part of GUI */);
shared$.subscribe(data => /** display data in another part of GUI */);

AsyncProcess.(static)on

AsyncProcess.on returns an TriggeredProcess that is triggered by the given trigger$ observable.

import { AsyncProcess } from 'rombok';
import { Subject } from 'rxjs';

const trigger$ = new Subject<string>();
const asyncProcess = new AsyncProcess.on(
    trigger$,
    endpoint => fromFetch('https://url/' + endpoint),
);

const shared$ = asyncProcess.share('todos')

shared$.subscribe(data => /** display data in GUI */);

AsyncProcess.(static)immediately

AsyncProcess.immediately returns an TriggeredProcess that is triggered immediately when subscribed to its share or execute.

import { AsyncProcess } from 'rombok';
import { Subject } from 'rxjs';

const immediatelyTriggeredProcess = new AsyncProcess.on(
    endpoint => fromFetch('https://url/' + endpoint),
);

const observable$ = immediatelyTriggeredProcess.execute('todos')

observable$.subscribe(data => /** display data in GUI */);

Process (@Deprecated)

Process is a stream holder, that includes success$, inProgress$ and error$ stream with which the lifecycle of an async process can be described.

import { Process } from 'rombok';

const process = new Process();

process.execute(() => fromFetch('https://url')).subscribe({
    next: () => {/** some declarative logic (eg. reroute after from submition) */},
    error: () => {/** some declarative error handling (eg. log to console and rethrow to global error reporting)*/}
}));

process.success$.subscribe(data => /** display data */);
process.inProgress$.subscribe(isLoading => /** show/hide loader */);
process.error$.subscribe(errorOrNull => /** show/hide error state */);

BoundProcess

Is same as process, but the loading function is always the same. With process one can do the following:

import { Process } from 'rombok';

const process = new Process();
$button1.onclick = () => process.execute(() => fromFetch('url1')).subscribe();
$button2.onclick = () => process.execute(() => fromFetch('url2')).subscribe();

With bound process you can reuse the common logic - less code.

import { BoundProcess } from 'rombok';

const process = new BoundProcess(url => fromFetch(url));
$button1.onclick = () => process.execute('url1').subscribe();
$button2.onclick = () => process.execute('url2').subscribe();

Process options

MULTIPLE_EXECUTIONS_STRATEGY

How to deal with multiple calls to execute. See rxjs switchMap, mergeMap, concatMap By default: MERGE_MAP

// by default it uses MULTIPLE_EXECUTIONS_STRATEGY.MERGE_MAP
// that is the same as using mergeMap to handle the calls to process.execute()
const mergeProcess = new Process({ 
    multiple_executions_strategy: MULTIPLE_EXECUTIONS_STRATEGY.MERGE_MAP,  
});
process.execute(() => delay(200).pipe(mergeMap(() => of(1)))).subscribe();
process.execute(() => delay(100).pipe(mergeMap(() => of(2)))).subscribe();
// only the second request will resolve, the total execution time is 200 ms

// MULTIPLE_EXECUTIONS_STRATEGY.SWITCH_MAP
// that is the same as using switchMap to handle the calls to process.execute()
const switchProcess = new Process({ 
    multiple_executions_strategy: MULTIPLE_EXECUTIONS_STRATEGY.SWITCH_MAP,  
});
process.execute(() => delay(200).pipe(mergeMap(() => of(1)))).subscribe();
process.execute(() => delay(100).pipe(mergeMap(() => of(2)))).subscribe();
// first the second request will resolve, than the first, the total execution time is 200 ms

// MULTIPLE_EXECUTIONS_STRATEGY.CONCAT_MAP
// that is the same as using mergeMap to handle the calls to process.execute()
const mergeProcess = new Process({ 
    multiple_executions_strategy: MULTIPLE_EXECUTIONS_STRATEGY.CONCAT_MAP,  
});
process.execute(() => delay(200).pipe(mergeMap(() => of(1)))).subscribe();
process.execute(() => delay(100).pipe(mergeMap(() => of(2)))).subscribe();
// first the first request will resolve, than the second, the total execution time is 300 ms

The same options apply to BoundProcess.

Development

Clone and npm install

Test

npm run test

Build

npm run build

Bundle in /library/dist