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

@effectful/es

v1.4.10

Published

Standard JavaScript effects using @effectful/core (abstract interface)

Downloads

389

Readme

@effectful/es

The two-level abstract syntax for effects based on ECMAScript async, generator and async generator functions syntax overloading.

The project is a babel plugin for integrating new custom computational effects into JavaScript.

By default, it is yet another implementation of ECMAScript async, generator and async generator functions, but it also can be extended.

The project is a part of EffectfulJS tool chain.

Why

Here is a list of things not available with native or other transpiler implementations:

  • Abstract API - can be re-implemented or amended for your purposes
  • Custome Concrete API for better performance
  • Persistent state
  • Implicit parallelism
  • Deriving program's graph for static analysis

Usage

Abstract interface

$ npm install --save-dev @effectful/es
$ npm install --save @effectful/es-rt

For example:

{
  "plugins": ["@effectful/es/transform"]
}

Or:

$ babel --plugins @effectful/es/transform index.js

By default it injects imports for @effectful/es-rt.

It is an implementation of the abstract interface for EcmaScript async, generators and async functions. The interface doesn't yet have documentation. The default implementation is pretty small and can be used as a reference for now. There is importRT option to pass some overloaded concrete implementations libraries.

{
  "plugins": [["@effectful/es/transform",{"importRT":"my-custom-effects"}]]
}

Zero-config transformation

Zero-configuration using babel-plugin-macros, or any other tool where it is enabled by default (such as Create Reat App since v2).

Just import "@effectful/es/macro" module in the module you want to transpile.

Inlined concrete implementation

$ npm install --save-dev @effectful/es
$ npm install --save @effectful/es-inline-rt

This .babelrc

{
  "plugins": [["@effectful/es/transform",{"inline":true}]]
}

It is a much faster implementation, but there is no way to overload anything.

Other options are:

  • loose - like inline but it also drops a few ECMAScript compatibility features to make the generated code even more smaller and faster
  • defunct - if true state is encoded as number and a there is a single function to move between states; otherwise, the state is a state transition function callback
  • topLevel - if true moves state transition functions outside original function's body
  • par - enables implicit parallelism. It doesn't yet work with "inline", "loose" and "topLevel"

There are quite a few of lower level options described in config.js.

Their values can be provided using all, file, pure, effectful, generators, async, asyncGenerators fields in the plugin options. For example, to use CommonJS modules instead of defaulting ES for runtime injection use:

{
  "plugins": [["@effectful/es/transform",{"file":{"modules":"commonjs"}}]]
}

Implicit parallelism

If enabled the compiler will locate "par" and "seq" in the beginning of the block to switch between parallel and sequential mode resp.

For example:

async function parDemo() {
  "par";
  const a = await A;
  const b = await B(a);
  const c = await C;
}

ESLint complains about not used expressions, so as an alternative to the directives there is profile function which expects a single string literal parameter ("par" or "seq"):

import * as M from "@effectful/es"

async function parDemo() {
  M.profile("par");
  const a = await A;
  {
    M.profile("seq")
    const b = await B;
    const c = await C;
  }
}

Cancelation

By default, the runtime also adds M.cancelSymbol property to each returned Promise. It is a function and it tries to stop the execution of the corresponding async function. The cancelation is propagated to await expressions if they have this method, but it isn't propagated to children.

There is also a helper function M.cancel which simply calls promise[M.cancelSymbol]() if it exists.

LICENSE

Distributed under the terms of The MIT License (MIT).