GithubHelp home page GithubHelp logo

garronej / evt Goto Github PK

View Code? Open in Web Editor NEW
444.0 6.0 6.0 13.02 MB

💧EventEmitter's typesafe replacement

Home Page: https://evt.land

License: MIT License

TypeScript 99.79% JavaScript 0.21%
eventemitter nodejs browser async-await promise typescript deno react-native node

evt's Introduction

💧EventEmitter's typesafe replacement💧

Home - Documentation


'evt' is intended to be a replacement for 'events'.
It makes heavy use of typescript's type inference features to provide type safety while keeping things concise and elegant 🍸.

Suitable for any JS runtime env (deno, node, old browsers, react-native ...)

Can be imported in TypeScript projects using version TypeScript >= 3.8 (February 20th, 2020) and in any plain JS projects.

NOTE: There is very few breaking changes from v1 to v2. Check them out.

Who is using it


Install / Import

In Deno:

import { Evt } from "https://deno.land/x/evt/mod.ts";

Anywhere else:

$ npm install --save evt
import { Evt } from "evt"; 

Try it

Playground

Motivations

There are a lot of things that can't easily be done with EventEmitter:

  • Enforcing type safety.
  • Removing a particular listener ( if the callback is an anonymous function ).
  • Adding a one-time listener for the next event that meets a condition.
  • Waiting (via a Promise) for one thing or another to happen.
    Example: waiting at most one second for the next message, stop waiting if the socket disconnects.

Why would someone pick EVT over RxJS:

  • EVT's learning curve is not as steep as RxJS's.
  • Generates code that is easier to grasp for people not familiar with reactive programming.

EVT is an attempt to address all these points while trying to remain as accessible as EventEmitter.


Get Started

The sticker

Shop

evt's People

Contributors

cmorten avatar dependabot[bot] avatar garronej avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

evt's Issues

Support esm module in node

Is your feature request related to a problem? Please describe.
cannot use evt in node esm module

import { Evt } from 'evt';
         ^^^
S module, which may not support all module.exports as named exports.CommonJS modules can always be imported via the default export, for example using:

import pkg from 'evt';
const { Evt } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:179:5)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5)
    at async handleMainPromise (node:internal/modules/run_main:63:12)

Describe the solution you'd like
evt could use tsup to support a esm dist

Additional context
the minimal repetition: https://github.com/SOVLOOKUP/rubickbase/tree/master/example

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository.

  • WARN: Found renovate config warnings

This repository currently has no open or pending branches.

Detected dependencies

npm
package.json
  • minimal-polyfills ^2.2.1
  • run-exclusive ^2.2.14
  • tsafe ^0.10.0
  • @types/react ^18.0.15
  • react ^18.2.0
  • rxjs ^6.5.4
  • @types/node ^10.0.0
  • typescript ^4.2.3
  • denoify ^0.11.2

  • Check this box to trigger a request for Renovate to run again on this repository

EvtLikeToEvt

[ ]: Use StatefulEvtLike in powerhooks instead of StatefulObservable.

//evtLikeToEvt.ts
import type { NonPostableEvtLike, UnpackEvt, EvtLike } from "./types";
import { importProxy } from "./importProxy";
import type { EvtLikeToEvt } from "./types";
import { assert } from "tsafe/assert";
import { is } from "tsafe/is";

type CtxLike<Result> = import("./types").CtxLike<Result> & {
    evtDoneOrAborted: NonPostableEvtLike<unknown> & { postCount: number; attachOnce(callback: () => void): void; };
};

export function evtLikeToEvt<E extends NonPostableEvtLike<any>>(
		evtLike: E,
		ctx: CtxLike<any>
): EvtLikeToEvt<E> {

	const evt = "state" in evtLike ? importProxy.Evt.create((evtLike as any).state) : importProxy.Evt.create();

	let doSkip = false;

	evt.attach(ctx, data => {
		//NOTE: We received an event so we know it's postable;
		assert(is<EvtLike<UnpackEvt<E>>>(evtLike));
		doSkip = true;
		evtLike.post(data);
		doSkip = false;
	});

	const ctxForEvtLike = importProxy.Evt.newCtx();

	evtLike.attach(ctxForEvtLike, data => {
		if (doSkip) {
			return;
		}
		evt.post(data);
	});

	ctx.evtDoneOrAborted.attach(() => ctxForEvtLike.done());

	return evt as any;

}

Webpack target ES5

Hi!

First, congratulations for this library.
I'm making another library where there are extended classes from Evt. I use rollup to build with params:

rollup -> format: es
tsconfig -> module: ES2015, target: ES6

This library run ok!

Then, I use this library in other project under webpack.

Some params are:

tsconfig -> target: ES5

webpack build ok!

But running my final app there is a error:

TypeError: Class constructor MyClass cannot be invoked without 'new'

What is the problem?
Thanks!

EventEmitter to evt sample.

Hi,

can you provide conversion list from EventEmitter to Evt ?

should we extend Evt in ours class ?
is this.emit(type, parma) should be replace by a this.evt.push([type, param])
is obj.on('event', (params) => {do stuff}) become evtText.attach???
is obj.once('event', (params) => {do stuff}) become evtText.attachOnce???
and where is the detach ?

Support Deno 1.4.0 stricter type checks

Is your feature request related to a problem? Please describe.

Deno 1.4.0 introduced stricter type checks for all users using the --unstable flag. These (presumably) will be integrated with Deno stable in an upcoming release. This request is to make the necessary changes to support these stricter checks.

See relevant section in release blog post: https://deno.land/posts/v1.4#stricter-type-checks-in-code--unstablecode

Specifically r.e. import and export of types.

Describe the solution you'd like

Import and export all types using the stricter syntax:

// Bad
import { MyType } from "./mod.ts";
export { MyType } from "./mod.ts";

// Good
import type { MyType } from "./mod.ts";
export type { MyType } from "./mod.ts";

Describe alternatives you've considered

--

Additional context

GitHub release notes 1.4.0: https://github.com/denoland/deno/releases/tag/v1.4.0

Faced the following errors when attempting to upgrade Opine to use Deno 1.4.0 and run an example using unstable APIs. These errors should stand as a good starting point for finding all places which require changes:

error: TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { AsyncReturnType } from "./AsyncReturnType.ts";
         ~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/tools/typeSafety/index.ts:2:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { UnpackPromise } from "./UnpackPromise.ts";
         ~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/tools/typeSafety/index.ts:8:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { UnpackTypeGuard } from "./UnpackTypeGuard.ts";
         ~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/tools/typeSafety/index.ts:9:10

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Operator } from "./Operator.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/Handler.ts:1:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Handler } from "../Handler.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/CtxLike.ts:2:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Operator } from "../Operator.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/StatefulReadonlyEvt.ts:2:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Handler } from "../Handler.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/NonPostableEvt.ts:1:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Operator } from "../Operator.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/NonPostableEvt.ts:2:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Handler } from "../Handler.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/Ctx.ts:2:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Handler } from "../Handler.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/VoidCtx.ts:2:1

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { Ctx, DoneOrAborted } from "./Ctx.ts";
         ~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:1:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { Ctx, DoneOrAborted } from "./Ctx.ts";
              ~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:1:15

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { CtxLike, VoidCtxLike } from "./CtxLike.ts";
                  ~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:2:19

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { Evt } from "./Evt.ts";
         ~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:3:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { NonPostableEvt } from "./NonPostableEvt.ts";
         ~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:4:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { Postable } from "./Postable.ts";
         ~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:5:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { StatefulEvt } from "./StatefulEvt.ts";
         ~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:6:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { StatefulReadonlyEvt, StateDiff as Diff } from "./StatefulReadonlyEvt.ts";
         ~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:7:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { StatefulReadonlyEvt, StateDiff as Diff } from "./StatefulReadonlyEvt.ts";
                              ~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:7:31

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { StatefulPostable } from "./StatefulPostable.ts";
         ~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:8:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { VoidCtx } from "./VoidCtx.ts";
         ~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:9:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { VoidEvt } from "./VoidEvt.ts";
         ~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:10:10

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { SwapEvtType } from "./SwapEvtType.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/helper/FactorizeEvt.ts:2:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { UnpackEvt } from "./UnpackEvt.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/helper/FactorizeEvt.ts:3:1

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { FactorizeEvt } from "./FactorizeEvt.ts";
         ~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/helper/index.ts:1:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { SwapEvtType } from "./SwapEvtType.ts";
         ~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/helper/index.ts:2:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { ToPostableEvt } from "./ToPostableEvt.ts";
         ~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/helper/index.ts:3:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { ToNonPostableEvt } from "./ToNonPostableEvt.ts";
         ~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/helper/index.ts:4:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { UnpackCtx } from "./UnpackCtx.ts";
         ~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/helper/index.ts:5:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { UnpackEvt, EvtLike } from "./UnpackEvt.ts";
         ~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/helper/index.ts:6:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { UnpackEvt, EvtLike } from "./UnpackEvt.ts";
                    ~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/helper/index.ts:6:21

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { Handler } from "./Handler.ts";
         ~~~~~~~
    at https://deno.land/x/[email protected]/lib/types/index.ts:5:10

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Operator } from "../../types/Operator.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/util/genericOperators/to.ts:1:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { FactorizeEvt } from "./types/helper/FactorizeEvt.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.factorize.ts:2:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { UnpackEvt } from "./types/helper/UnpackEvt.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.merge.ts:1:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import * as dom from "./types/lib.dom.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.from.ts:7:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { ToPostableEvt } from "./types/helper/ToPostableEvt.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.asPostable.ts:2:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { UnpackEvt } from "./types/helper/UnpackEvt.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.asyncPipe.ts:3:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { SwapEvtType } from "./types/helper/SwapEvtType.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.asyncPipe.ts:4:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { ToNonPostableEvt } from "./types/helper/ToNonPostableEvt.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.asNonPostable.ts:2:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Handler } from "./types/Handler.ts"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.parsePropsFromArgs.ts:2:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Operator } from "./types/Operator.ts"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.parsePropsFromArgs.ts:3:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { SwapEvtType } from "./types/helper/SwapEvtType.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.loosenType.ts:1:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { UnpackEvt } from "./types/helper/UnpackEvt.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.loosenType.ts:2:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Handler } from "./types/Handler.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Evt.ts:29:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { CtxLike } from "./types/interfaces/CtxLike.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/StatefulEvt.ts:9:1

TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { Handler } from "./types/Handler.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/x/[email protected]/lib/Ctx.ts:7:1

Happy to try to submit a PR 😄

Package path ./lab/overwriteReadonlyProp is not exported from package node_modules/tsafe

When I try to use Evt with [email protected] and @vue/[email protected] I get the errors below.

I'm not too sure what the issue is so any help would be greatly appreciated. I did find this issue which I think is related vuejs/vue-cli#7144.

ERROR Failed to compile with 1 error
error in ./node_modules/evt/lib/Ctx.js

Module not found: Error: Package path ./lab/overwriteReadonlyProp is not exported from package /home/office-app/node_modules/tsafe (see exports field in /home/office-app/node_modules/tsafe/package.json)

ERROR in ./node_modules/evt/lib/Ctx.js 33:30-72
Module not found: Error: Package path ./lab/overwriteReadonlyProp is not exported from package /home/office-app/node_modules/tsafe (see exports field in /home/office-app/node_modules/tsafe/package.json)
 @ ./node_modules/evt/lib/index.js 20:12-28
 @ ./src/services/active-org-service.ts 15:0-26 118:31-34
 @ ./src/App.ts 35:0-65 146:21-51
 @ ./src/main.ts 18:0-24 45:13-16

ERROR in ./node_modules/evt/lib/Evt.js 126:30-72
Module not found: Error: Package path ./lab/overwriteReadonlyProp is not exported from package /home/office-app/node_modules/tsafe (see exports field in /home/office-app/node_modules/tsafe/package.json)
 @ ./node_modules/evt/lib/index.js 22:12-28
 @ ./src/services/active-org-service.ts 15:0-26 118:31-34
 @ ./src/App.ts 35:0-65 146:21-51
 @ ./src/main.ts 18:0-24 45:13-16

ERROR in ./node_modules/evt/lib/LazyEvt.js 4:30-72
Module not found: Error: Package path ./lab/overwriteReadonlyProp is not exported from package /home/office-app/node_modules/tsafe (see exports field in /home/office-app/node_modules/tsafe/package.json)
 @ ./node_modules/evt/lib/Ctx.js 31:16-36
 @ ./node_modules/evt/lib/index.js 20:12-28
 @ ./src/services/active-org-service.ts 15:0-26 118:31-34
 @ ./src/App.ts 35:0-65 146:21-51
 @ ./src/main.ts 18:0-24 45:13-16

ERROR in ./node_modules/evt/lib/LazyStatefulEvt.js 4:30-72
Module not found: Error: Package path ./lab/overwriteReadonlyProp is not exported from package /home/office-app/node_modules/tsafe (see exports field in /home/office-app/node_modules/tsafe/package.json)
 @ ./node_modules/evt/lib/StatefulEvt.js 46:24-52
 @ ./node_modules/evt/lib/index.js 24:20-44
 @ ./src/services/active-org-service.ts 15:0-26 118:31-34
 @ ./src/App.ts 35:0-65 146:21-51
 @ ./src/main.ts 18:0-24 45:13-16

ERROR in ./node_modules/evt/tools/Deferred.js 19:30-72
Module not found: Error: Package path ./lab/overwriteReadonlyProp is not exported from package /home/office-app/node_modules/tsafe (see exports field in /home/office-app/node_modules/tsafe/package.json)
 @ ./node_modules/evt/lib/Evt.js 128:17-45
 @ ./node_modules/evt/lib/index.js 22:12-28
 @ ./src/services/active-org-service.ts 15:0-26 118:31-34
 @ ./src/App.ts 35:0-65 146:21-51
 @ ./src/main.ts 18:0-24 45:13-16

webpack compiled with 5 errors
No issues found.

instead of RxJS but didn't support 'window' events

I was use rxjs fromEvent to subscribe 'resize' event, and used Evt.from(window, 'resize') instead of it. But it's not work. I have tried other sample like 'window.click', rxjs is works fine but nothing happening in Evt.

Does Evt.from support window events?

OS: Mac
Browser: Chrome

Extending Evt

Hello,

This is merely a question, no really an issue. What would be the recommended approach if I wanted to have a class that can be used as an Evt?

Some options come to mind:

  1. Extend Evt. I could not find any docs about it so not sure if possible or recommended. Restrictive since it does not allow me to extend from anything else.
  2. Wrap an Evt instance and expose a reduced API. Some doc about how to do it this way would be great.
  3. Extend the Evt interface, wrap an instance and delegate the implementation to the wrapped instance. If this could be done in a simple way, this would be awesome because it does not disrupt my own inheritance.
  4. Using mixins. In theory this could achieve something similar to the previous option, possibly better?. More information here and here

Appreciate any information about this. Thanks

Require cycles

Require cycle: node_modules/evt/dist/lib/Evt.js -> node_modules/evt/dist/lib/EvtCore.js -> node_modules/evt/dist/lib/Ctx.js -> node_modules/evt/dist/lib/util/getLazyEvtFactory.js -> node_modules/evt/dist/lib/Evt.js

Require cycle: node_modules/evt/dist/lib/EvtCore.js -> node_modules/evt/dist/lib/Ctx.js -> node_modules/evt/dist/lib/util/getLazyEvtFactory.js -> node_modules/evt/dist/lib/EvtCore.js

Require cycle: node_modules/evt/dist/lib/Evt.js -> node_modules/evt/dist/lib/util/merge.js -> node_modules/evt/dist/lib/Evt.js

Evt is not support MediaQueryList event

Im use useEvt in my react app to listening every DOM events. But it throw exception with follow code:

const mql = window.matchMedia('(max-width: 600px)')
useEvt(
  ctx => {
    Evt.from(ctx, mql, 'change').attach(...)
  },
  []
)

Will Evt support MediaQueryList event?

v3 roadmap

  • Get rid of the need to add the $ when attaching with operator.
  • Support for async operators ( other than with "evt/asyncPipe").
  • Create SelfManaged operators for more complex operation.
  • StatefulEvt: Get rid of evtDiff, evtChange, evtChangeDiff the onlyWhenChanged operator is preferable.
  • Way (via an operator) to get from an evt a new instance that only postAsyncOnceHandled.
  • We should be able to create StatefullEvt where the initial state is only computer when accessed Evt.create(()=> "initial state" )
  • ctx.evtDoneOrAborted() should be a StatefulEvt

Feature similar to `distinct` in RxJs

Is your feature request related to a problem? Please describe.
I need have my Evt event emitter be idempotent since the source can emit duplicate events.

Describe the solution you'd like
I'd love a pipe-like operator that can filter for events that have already been emitted.

Describe alternatives you've considered
RxJs has a distinct operator that does exactly what I need. Since I'm already using Evt and I like the library, I'd like to continue using it if possible.

Additional context

Allow waitFor() return an AsyncIterator

What problem it solves

The possibility to wait for event's series like as example time based events

Possible Solution

I've considered to create a new method waitForEvents that return an AsyncIterator allowing the consumer to consume "events' serie" using for await statement.

Pilot implementation

interface EventIterator<T> extends AsyncIterable<T>  {
    stop(): void
}

function waitForEvents<T>(  evt: Evt<T> , timeout?: number ): EventIterator<T> {

    let isStopped = false
    async function* events() {
        
        while(!isStopped) {
            try{
                const res =  await evt.waitFor( timeout )
                yield res

            } catch(error) {
                console.warn("TIMEOUT!");
                isStopped = true
            }
        }
    }

    return {
        [Symbol.asyncIterator]: () => events(),
        stop: () => isStopped = true
    }
}

Run the Proof-of-Concept

Operator BufferTime

Hello,

I'm looking to use Evt with my production codebase. The limited number of available operators could be a blocker for adoption. Could you please help me understand how hard it would be to add some of the available RxJS operators?

Here is one I'd like to have:
https://www.learnrxjs.io/learn-rxjs/operators/transformation/buffertime

If it is fairly easy to implement these operators using Evt, maybe we can continue our plan to use Evt in production.

TYIA!

Odd type behavior on using to with attach

Type declarations

export type MutateResult<Item> = [Item[], Item[], Partial<Item>];

export type Result<Op extends Ops, Item> = Op extends "insert" ? Item[]
  : Op extends "get" ? Item
  : Op extends "remove" ? MutateResult<Item>
  : Op extends "update" ? MutateResult<Item>
  : Op extends "filter" ? MutateResult<Item>
  : unknown;

public $all = Evt.create<
    | ["get", Result<"get", Item>]
    | ["filter", Result<"filter", Item>]
    | ["insert", Result<"insert", Item>]
    | ["remove", Result<"remove", Item>]
    | ["update", Result<"update", Item>]
  >();

Actual code

// Book is the Generic Item type here
interface Book {
    id: number;
    title: string;
    description: string;
    author: string;
}

book.$all.attach(to("update"), (item) => {
  // on above
})

Error

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'Stateless<["get", Book] | ["filter", MutateResult<Book>] | ["insert", Book[]] | ["remove", MutateResult<Book>] | ["update", MutateResult<...>], MutateResult<...>, never>' is not assignable to parameter of type 'number'.ts(2769)
78d5007fefc918e5af7da7c1f79a43727886c85bce6496e0fb1ad9b2255fa941(557, 5): The last overload is declared here.

the latest release breaks denoify

Hi! I think the latest release of evt might have broken denoify; running denoify gives this error:

Error: Cannot find module '/***/node_modules/denoify/node_modules/evt/dist/tools/reducers/partition.js'
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:1060:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:1053:15)
    at resolveExports (node:internal/modules/cjs/loader:538:14)
    at Module._findPath (node:internal/modules/cjs/loader:607:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1025:27)
    at Module._load (node:internal/modules/cjs/loader:885:27)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/***/node_modules/denoify/lib/denoify.js:16:21)
    at Module._compile (node:internal/modules/cjs/loader:1218:14) {
  code: 'MODULE_NOT_FOUND',
  path: '/***/node_modules/denoify/node_modules/evt/package.json'
}

I think that's because in this commit 2a2cd58 you forgot to add dist/* to the files array in package.json. So trying to run this line of code https://github.com/garronej/denoify/blob/425336e1901948ca1ff07c509ef11d80c4032995/src/lib/denoify.ts#L13 resolves to evt/dist/tools/reducers/partition.js which doesn't exist in the published package.

My workaround is to use yarn's resolutions field and add "denoify/evt": "2.4.18" so it resolves to an older version.

Assets

2020-01-05 16-22-48
TODO: Il faut pour que le second wait for reçoive l'évent qu'il ait été attaché après que le premier ait résolu. Dans le cas contraire, on se retrouve à choper des événements du passé.
Fixed, see test36

After upgrading to Deno v1.9.0, running project results in TS2612 error

I'm attempting to run a project, and the resulting error links to this module.

My project has the following dependencies:

  • deno.land/std/path
  • deno.land/x/opine
  • deno.land/x/http_errors
  • deno.land/x/dejs
  • deno.land/x/jsonfile
  • deno.land/x/denodb

Simply running deno run --allow-all mod.ts, which worked before upgrading to Deno v1.9.0, now exits with the following error:

TS2612 [ERROR]: Property 'resolve' will overwrite the base property in 'Deferred<undefined>'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.
    public readonly resolve!: () => void;
                    ~~~~~~~
    at https://deno.land/x/[email protected]/tools/Deferred.ts:57:21

I'm not sure which dependency may be invoking this line, and I haven't used evt directly. Trying to debug with the --inspect and --inspect-brk flags yielded no results in my case.

Create a new Evt after applying filter/operator

I'm using Evt together with Pothos graphql subscriptions, where the subscribe method accepts an async iterator, which Evt instances are, great!

Except now I'm trying to apply a filter or transform for the subscription, so I would have

const pingEvent = new Evt<string | null>(null);
setInterval(() => pingEvent.post(`pong ${Date.now()}`), 1000);

and the schema

const schema = (builder: typeof builderType) => {
  builder.subscriptionField("ping", (t) =>
    t.string({
      resolve: (parent) => parent,
      subscribe: () => pingEvent,
    })
  );
};

This works decently, as soon as you subscribe you get the latest value from the stateful event, which is great. But what if the first state was not published yet? I don't want to return null on the graphql resolver.

I would like to be able to to something like

subscribe: () => pingEvent.attach(event => event !== null),

But I am not sure how to create a new instance of the Evt.

To create my own solution I attempted the helper method

export function applyEvtFilter<
  E extends Evt<any>,
  T extends (data: UnpackEvt<E>) => boolean
>(evt: E, operator: T) {
  const newEvt = new Evt<UnpackEvt<E>>();
  evt.attach(operator, (value) => newEvt.post(value));
  return newEvt;
}

and doing

subscribe: () => applyEvtFilter(pingEvent, event => event !== null))

And while this techincally works, it no longer unsubscribes, leading to eventually print

MaxHandlersExceededWarning: Possible Evt memory leak detected.26 handlers attached.

So, how am I able to apply operators to the event stream and return a new Evt that still properly unsubscribes?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.