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

succeed

v0.9.11

Published

`after` creates an object with a dual identity as both a Promise and an Observable. It's an RxJS Observable underneath, but exposes a `then` method, so can be awaited, or chained like a Promise.

Downloads

2

Readme

after - the async utility you didn't know you needed.

after creates an object with a dual identity as both a Promise and an Observable. It's an RxJS Observable underneath, but exposes a then method, so can be awaited, or chained like a Promise.

Here are some things you can create with it:

await after(1000)                 // A promise-like duration

after(1000, {data: {}})           // A mock endpoint return value

after(15*60*1000, logout)         // A deferred timer until a function call (an Observable)
   .subscribe()                   //  - Begin the timer
   .unsubscribe()                 //  - Stop the timer (logout will not be called)

concat(                           // A mock user-behavior (cancelable!)
  after(1000, () => fillEmail()),
  after(1000, () => fillPassword())
)

Installation

npm i -S succeed

import { after } from 'succeed';  // client or server

Overview

Allows you to:

  • Mix and match Promises and Observables.
  • Support cancelation without additional objects (AbortController, clearTimeout)
  • Create scripts with specific delays to test debouncing, etc.
  • Compose in a cancelation-preserving way

Example Use Cases


after is a Promise (a "thenable")

When used as you would a Promise, after() represents a delay, an value, or a value calculated after either a) a time in milliseconds, or b) a Promise.

await after(100) // only a delay

await after(100, {
    updatedAt: '2020-04-01'
})
await after(100, () => ({
    updatedAt: new Date()
}))

after(credentialPromise, user => logIn(user))
    .then(token => /* */ )

after is an Observable!

after is also an Observable, so you can obtain its value via, subscribe() , and cancel its subscription by calling .unsubscribe() . A stream with any desired timing can be created by concat -enating a bunch of after s.

after(100, 3.14).subscribe(pi => (setDiameter(radius * 2 * pi)))

after(0, 3.14).subscribe(pi => Math.TAU = 2 * pi);
// Math.TAU is immediately available because its after '0'

concat(
    after(0, Math.PI),
    after(1000, 2.718)
).subscribe(constant)

Passing 0 msec causes after to be a synchronous Observable.

For e2e and unit testing, and Storybook, in order to simulate component interaction precisely, it is useful to create a script by concatenating after s of user interactions, or other function invocations.

const sub = concat(
    after(0, () => userEvent.type(email, "[email protected]")),
    after(1000, () => userEvent.type(password, "password123"))
).subscribe()

// unsubscribe, and unstarted steps will not run
sub.unsubscribe();

Unlike Promises, which run to completion by design (they are a Promise after all), an after or a concat-enation of afters is fully cancelable! So if you unsubscribe() on component unmount, for example, the chain will be halted wherever it is.

Also unlike Promises, the Observable model assumes nothing about whether the execution is sync or async, or whether yielding zero- single- or multiple -values. Notifications are simply delivered whenever the Observable calls observer.next().

after can delay an Observable!

When the valueProducer argument is an Observable, after returns a delayed subscription to the Observable.

In contrast, RxJS delay only delays the notifications. The difference is when the underlying resource is actually used at subscription time, or only after the delay.


Conclusion

That's all - enjoy using after (and concat )!