diff --git a/.gitbook.yaml b/.gitbook.yaml deleted file mode 100644 index 768cfdaa..00000000 --- a/.gitbook.yaml +++ /dev/null @@ -1 +0,0 @@ -root: ./docs/ \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index dd84ea78..00000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - -**Additional context** -Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md deleted file mode 100644 index 48d5f81f..00000000 --- a/.github/ISSUE_TEMPLATE/custom.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: Custom issue template -about: Describe this issue template's purpose here. -title: '' -labels: '' -assignees: '' - ---- - - diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index bbcbbe7d..00000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index 04079c3b..00000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,102 +0,0 @@ -name: ci -on: - push: - branches: - - develop - pull_request: - branches: - - develop - -jobs: - - test_node: - runs-on: ubuntu-latest - if: ${{ !github.event.created }} - strategy: - matrix: - node: [ '13', '12', '11', '10', '8' ] - name: Test with Node v${{ matrix.node }} - steps: - - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node }} - - run: npm ci - - run: npm run build - - run: npm run test:node - - test_deno: - runs-on: ubuntu-latest - if: ${{ !github.event.created }} - name: test with Deno - steps: - - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - name: Cache - uses: actions/cache@v1 - with: - path: ~/.cache/deno - key: deno-${{ runner.os }}-${{ hashFiles('deno-lock.json') }} - restore-keys: | - deno-${{ runner.os }}-${{ hashFiles('deno-lock.json') }} - deno-${{ runner.os }}- - deno- - - uses: denolib/setup-deno@master - with: - deno-version: 1.x - - run: npm ci - - run: npm run build - - run: npm run test:deno - - trigger_publish: - name: Trigger publish.yaml workflow if package.json version updated ( and secrets.PAT is set ). - runs-on: ubuntu-latest - env: - PAT: ${{secrets.PAT}} - if: github.event_name == 'push' && github.event.head_commit.author.name != 'denoify_ci' - needs: - - test_node - - test_deno - steps: - - - name: Get version on master - id: v_master - uses: garronej/github_actions_toolkit@v1.2 - with: - action_name: get_package_json_version - owner: ${{github.repository_owner}} - repo: ${{github.event.repository.name}} - branch: master - compare_to_version: '0.0.0' - - - name: Get version on develop - id: v_develop - uses: garronej/github_actions_toolkit@v1.2 - with: - action_name: get_package_json_version - owner: ${{github.repository_owner}} - repo: ${{github.event.repository.name}} - branch: ${{ github.sha }} - compare_to_version: ${{steps.v_master.outputs.version || '0.0.0'}} - - - name: 'Trigger the ''publish'' workflow' - if: ${{ !!env.PAT && steps.v_develop.outputs.compare_result == '1' }} - uses: garronej/github_actions_toolkit@v1.2 - env: - GITHUB_TOKEN: ${{ secrets.PAT }} - with: - action_name: dispatch_event - owner: ${{github.repository_owner}} - repo: ${{github.event.repository.name}} - event_type: publish - client_payload_json: | - ${{ - format( - '{{"from_version":"{0}","to_version":"{1}","repo":"{2}"}}', - steps.v_master.outputs.version, - steps.v_develop.outputs.version, - github.event.repository.name - ) - }} diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml deleted file mode 100644 index aac7aa82..00000000 --- a/.github/workflows/publish.yaml +++ /dev/null @@ -1,114 +0,0 @@ -on: - repository_dispatch: - types: publish - -jobs: - update_changelog_and_sync_package_lock_version: - name: Update CHANGELOG.md and make sure package.json and package-lock.json versions matches. - runs-on: ubuntu-latest - steps: - - name: Synchronize package.json and package-lock.json version if needed. - uses: garronej/github_actions_toolkit@v1.2 - env: - GITHUB_TOKEN: ${{ secrets.PAT }} - with: - action_name: sync_package_and_package_lock_version - owner: ${{github.repository_owner}} - repo: ${{github.event.client_payload.repo}} - branch: develop - commit_author_email: denoify_ci@github.com - - name: Update CHANGELOG.md - if: ${{ !!github.event.client_payload.from_version }} - uses: garronej/github_actions_toolkit@v1.2 - env: - GITHUB_TOKEN: ${{ secrets.PAT }} - with: - action_name: update_changelog - owner: ${{github.repository_owner}} - repo: ${{github.event.client_payload.repo}} - branch_behind: master - branch_ahead: develop - commit_author_email: denoify_ci@github.com - exclude_commit_from_author_names_json: '["denoify_ci"]' - - publish_npm: - runs-on: ubuntu-latest - needs: update_changelog_and_sync_package_lock_version - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - run: npm ci - - run: npm run enable_short_import_path:npm - env: - DRY_RUN: "0" - - name: (DEBUG) Show how the files have been moved to enable short import - run: ls -lR - - name: Publishing on NPM - run: | - if [ "$(npm show $MODULE_NAME version)" = "$VERSION" ]; then - echo "This version is already published" - exit 0 - fi - if [ "$NPM_TOKEN" = "" ]; then - echo "Can't publish on NPM, You must first create a secret called NPM_TOKEN that contains your NPM auth token. https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets" - false - fi - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc - npm publish - rm .npmrc - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - MODULE_NAME: ${{ github.event.client_payload.repo }} - VERSION: ${{ github.event.client_payload.to_version }} - publish_deno: - runs-on: ubuntu-latest - needs: update_changelog_and_sync_package_lock_version - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - ref: develop - - name: Remove .github directory, useless on 'master' branch - run: rm -r .github - - name: Removes GitBook files - run: rm -r docs .gitbook.yaml - - name: Remove branch 'master' - continue-on-error: true - run: | - git branch -d master || true - git push origin :master - - name: Create the new 'master' branch - run: | - git branch master - git checkout master - git push origin master - - uses: actions/setup-node@v1 - - run: npm ci - - run: npm run enable_short_import_path:deno - env: - DRY_RUN: "0" - - name: Commit changes - run: | - git config --local user.email "denoify_ci@github.com" - git config --local user.name "denoify_ci" - git add -A - git commit -am "Automatic structural changes for Deno" - - name: Push changes - uses: ad-m/github-push-action@v0.5.0 - with: - github_token: ${{ secrets.PAT }} - branch: master - - name: Create Release - uses: garronej/create-release@master - env: - GITHUB_TOKEN: ${{ secrets.PAT }} - with: - tag_name: ${{ github.event.client_payload.to_version }} - release_name: Release ${{ github.event.client_payload.to_version }} - branch: master - draft: false - prerelease: false - - - - diff --git a/.gitignore b/.gitignore index f5d2e8a6..13be271a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,47 +1,2 @@ -# Logs -logs -*.log -npm-debug.log* - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules -jspm_packages - -# Optional npm cache directory -.npm - -# Optional REPL history -.node_repl_history - -dist/test -.vscode - -.DS_Store - - -/dist -/deno_dist -/mod.ts \ No newline at end of file + +/node_modules diff --git a/docs/.gitbook/assets/76691034-90204800-6646-11ea-8ef9-b07db8e39ca4.gif b/docs/.gitbook/assets/76691034-90204800-6646-11ea-8ef9-b07db8e39ca4.gif deleted file mode 100644 index 84e1a048..00000000 Binary files a/docs/.gitbook/assets/76691034-90204800-6646-11ea-8ef9-b07db8e39ca4.gif and /dev/null differ diff --git a/docs/.gitbook/assets/screenshot-2020-03-16-at-06.28.38 (1).png b/docs/.gitbook/assets/screenshot-2020-03-16-at-06.28.38 (1).png deleted file mode 100644 index a2f6d7c9..00000000 Binary files a/docs/.gitbook/assets/screenshot-2020-03-16-at-06.28.38 (1).png and /dev/null differ diff --git a/docs/.gitbook/assets/screenshot-2020-03-16-at-06.28.38.png b/docs/.gitbook/assets/screenshot-2020-03-16-at-06.28.38.png deleted file mode 100644 index a2f6d7c9..00000000 Binary files a/docs/.gitbook/assets/screenshot-2020-03-16-at-06.28.38.png and /dev/null differ diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index d70fc59b..00000000 --- a/docs/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Why EVT ? - -![](https://github.com/garronej/evt/workflows/ci/badge.svg?branch=develop) ![](https://img.shields.io/bundlephobia/minzip/evt) ![](https://img.shields.io/npm/dw/evt) ![](https://img.shields.io/github/commit-activity/w/garronej/evt) ![](https://img.shields.io/npm/l/evt) - -`'evt'` is intended to be a replacement for `'events'`. -It enables and encourages **functional programming** and 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 browser, react-native ...\)** - -* ✅ It is both a [Deno](https://deno.land/x/evt) and an [NPM](https://www.npmjs.com/evt) module. -* ✅ Lightweight, no dependency. -* ✅ No polyfills needed, the NPM module is transpiled down to ES3 - -Can be imported in TypeScript projects using version >= **3.4** \(Mar 2019\) and in any plain JS projects. - -## Motivation - -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._ - -Concerning RxJS: - -* It introduces a lot of abstractions. It's a big jump from `EventEmitter`. -* It is often needed to resort to custom [type guards](https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards), the filter operator [breaks the type inference.](https://stackblitz.com/edit/evt-795plc?embed=1&file=index.ts&hideExplorer=1) -* Tend to be quite verbose. -* It could be months before it eventually supports Deno. - -EVT is an attempt to address all these points while trying to remain as accessible as `EventEmitter`. - diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md deleted file mode 100644 index 21d4813b..00000000 --- a/docs/SUMMARY.md +++ /dev/null @@ -1,35 +0,0 @@ -# Table of contents - -* [Why EVT ?](README.md) -* [Overview](overview.md) -* [API Documentation](api/README.md) - * [Operator<T, U> \(type\)](api/operator.md) - * [Evt<T>](api/evt/README.md) - * [evt.\[$\]attach\*\(...\)](api/evt/attach.md) - * [evt.post\*\(data\)](api/evt/post.md) - * [evt.waitFor\(...\)](api/evt/waitfor.md) - * [evt.evt\[Attach\|Detach\]](api/evt/evtattachdetach.md) - * [evt.pipe\(...\)](api/evt/pipe.md) - * [evt.getHandlers\(\)](api/evt/gethandler.md) - * [evt.isHandled\(data\)](api/evt/ishandled.md) - * [evt.detach\(\[ctx\]\)](api/evt/detach.md) - * [evt.enableTrace\(...\)](api/evt/enabletrace.md) - * [evt.setMaxHandlers\(n\)](api/evt/setmaxhandlers.md) - * [toStateful\(initialState\)](api/evt/tostateful.md) - * [evt.getStatelessOp\(op\)](api/evt/getstatelessop.md) - * [Evt.create\(initalState?\)](api/evt/create.md) - * [Evt.newCtx<T>\(\)](api/evt/newctx.md) - * [Evt.getCtx\(object\)](api/evt/getctx.md) - * [Evt.from<T>\(...\)](api/evt/from.md) - * [Evt.useEffect\(...\)](api/evt/use-effect.md) - * [Evt.merge\(\[ evt1, evt2, ... \]\)](api/evt/merge.md) - * [Evt.loosenType\(evt\)](api/evt/loosentype.md) - * [Evt.factorize\(evt\)](api/evt/factorize.md) - * [Evt.asPostable\(evt\)](api/evt/aspostable.md) - * [Evt.asNonPostable\(evt\)](api/evt/asnonpostable.md) - * [Evt.setDefaultMaxHandlers\(n\)](api/evt/setdefaultmaxhandlers.md) - * [Ctx<T>](api/ctx.md) - * [StatefulEvt<T>](api/statefulevt.md) - * [Helper types](api/helpertypes.md) - * [Handler<T, U> \(type\)](api/handler.md) - diff --git a/docs/api/README.md b/docs/api/README.md deleted file mode 100644 index c8077b96..00000000 --- a/docs/api/README.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -description: >- - The API reference documentation of the library and step-by-step guide for new - users. ---- - -# API Documentation - -The [`Operator`](https://docs.ts-evt.dev/api-doc/operator) section is the place to start. - diff --git a/docs/api/ctx.md b/docs/api/ctx.md deleted file mode 100644 index a375ce44..00000000 --- a/docs/api/ctx.md +++ /dev/null @@ -1,282 +0,0 @@ -# Ctx<T> - -`Ctx` helps detach all `Handler`s that were attached in the goal of acompishing a certain task once the said task is done or aborted. - -{% hint style="info" %} -Get Ctx instance using[`Evt.newCtx()`](https://docs.evt.land/api/evt/newctx) or [`Evt.getCtx(obj)`](https://docs.evt.land/api/evt/getctx)\`\` -{% endhint %} - -{% hint style="info" %} -The only difference between `CtxVoid` and `Ctx` is that `ctxVoid.done()` can be called without argument when `ctx.done()`must be called with an argument \(`null` or `undefined`\). -{% endhint %} - -## `ctx.done([result])` - -Detach, from the `Evt` instances they are attached to, all Handlers bound to the context. - -Calling this method causes the `Evt` returned by `ctx.getEvtDone()` to be posted. - -{% hint style="info" %} -When an fλ operator return `{ "DETACH": ctx }`, `ctx.done()` is invoked. - -When it returns `{ "DETACH": ctx, "res": result }`, `ctx.done(result)` is invoked. -{% endhint %} - -{% hint style="info" %} -To test if ctx.done\(\) have been invoked already you can use:`ctx.getEvtDone().postCount !== 0` -{% endhint %} - -### Returns - -`ReturnType` All the [Handler](https://docs.ts-evt.dev/api/handler)s that were bound to the context. They are now detached, calling `ctx.getHandler()` just after `ctx.done()` returns an empty array. - -### Parameter - -* `T` for `Ctx` -* none for `VoidCtx` - -## `ctx.abort(error)` - -Equivalent of `ctx.done()` to use when the task did not go through. - -{% hint style="info" %} -When a fλ operator returns `{ "DETACH": ctx, "err": error }`, `ctx.abort(error)` is invoked. -{% endhint %} - -### Returns - -`ReturnType` \(cf `ctx.done` \) - -### Parameter - -`Error` an error that describes what went wrong. - -## `ctx.evtDoneOrAborted` - -Tracks when ctx.done or ctx.abort are invoked. - -{% hint style="info" %} -For most use cases, it is more convenient to use `ctx.waitFor([timeout])` -{% endhint %} - -### Returns - -* For VoidCtx an Evt that posts: - * `{ handlers: Handler.WithEvt[] }` when `ctx.done()` is called. - * `{ error: Error, handlers: Handler.WithEvt[] }` when `ctx.abort(error)` is called. -* For `Ctx`, an `Evt` that post: - * `{ result: Result; handlers: Handler.WithEvt[]; }` when `ctx.done(result)` is called. - * `{ error: Error, handlers: Handlers.WithEvt[]; }` when `ctx.abort(error)` is called. - -`Handler.WithEvt` is just a type alias for an object that wraps a handler and the `Evt` it is attached to: `{ handler: Handler, evt: Evt }` - -### Example - -```typescript -import { Evt } from "evt"; -import { EventEmitter } from "events"; - -const ctx= Evt.newCtx(); - -const evtText = new Evt(); -const evtTime = new Evt(); - -evtText.$attach( - text=> [ text.length ], - ctx, - count => console.log("1: " + count) -); - -evtTime.waitFor( - time => time < 0, - ctx, -).then(time=> console.log("2: " + time)); - -evtText - .pipe(ctx) - .pipe(text => [text.toUpperCase()]) - .attach(upperCaseText=> console.log("3: " + upperCaseText)) - ; - -Evt.merge(ctx, [ evtText, evtTime ]) - .attach(textOrTime => console.log("4: " + textOrTime)) - ; - -const ee= new EventEmitter(); - -Evt.from(ctx, ee, "text") - .attach(text=> console.log("5: " + text)) - ; - - -evtText.post("foo"); //Prints "1: 3" "3: FOO" "4: foo" -ee.emit("text", "bar"); //Prints "5: bar" - -console.log(evtText.getHandlers().length); //Prints "3" -console.log(evtTime.getHandlers().length); //Prints "2" - -console.log(ee.listenerCount("text")); //Print "1" - -ctx.evtDoneOrAborted.attachOnce( - ({handlers})=> { - - console.log( - handlers.filter(({ evt })=> evt === evtText).length + - " handlers detached from evtText" - ); - - console.log( - handlers.filter(({ evt })=> evt === evtTime).length + - " handlers detached from evtTime" - ); - - console.log( - handlers.length + " handlers detached total" - ); - - } -); - -//Prints: -//"3 handlers detached from evtText" -//"2 handlers detached from evtTime" -//"5 handlers detached total" -ctx.done(); - -console.log(evtText.getHandlers().length); //Prints "0" -console.log(evtTime.getHandlers().length); //Prints "0" -console.log(ee.listenerCount("text")); //Print "0" - -evtText.post("foo"); //Prints nothing -ee.emit("text", "bar"); //Prints nothing -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-niwafz?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -## `ctx.waitFor([timeout])` - -Tracks via a Promise that resolves when `ctx.done()` or `ctx.abort()` is invoked. - -### Returns - -`Promise` \(`T` is the type argument of `Ctx` \) A promise that resolve when ctx.done\(\[result\]\) is invoked. - -If `ctx.abort(error)` is invoked before `ctx.done()` the promise rejects with `error`. - -If timeout was specified the promise rejects if `ctx.done()` was not invoked within `timeout` milliseconds. If it happens `ctx.abort(timeoutError)` is internally invoked `timeoutError` being an instance of `EvtError.Timeout`. - -### Parameter - -`number` Optional, number of milliseconds before the promise reject if it hasn't fulfilled within this delay. - -## `ctx.getHandlers()` - -### Returns - -`Handler.WithEvt[]` The [`Handler`](https://docs.ts-evt.dev/api/handler)s that are bound to the context alongside with the `Evt` instance each one is attached to. The Handlers that are bound to the context but no longer attached to an Evt are not listed \( they are usually freed from memory anyway as there should be nor reference left of them as soon as they are detached \). - -### Example - -```typescript -//NOTE: Equivalent to evt.detach(ctx); -ctx - .getHandlers() - .filter(({ evt }))=> evt === evtString) - .forEach(({ handler })=> handler.detach()) - ; -``` - -## `ctx.evtAttach` - -### Returns - -`Evt>` An Evt that posts every time a new handler bound to the context is attached. - -```typescript -import { Evt } from "evt"; - -const evtText = new Evt(); - -const ctx= Evt.newCtx(); - -ctx.evtAttach.attach(handler => console.log(handler.timeout)); - -const timeout = 43; - -evtText.attach(timeout, ()=>{}); //Prints "43" -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-t17qsy?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -## `ctx.evtDetach` - -Same as `ctx.getEvtAttach()` but post when handlers are detached. Note that a handler being detached does not mean that it has been explicitly detached. One-time handlers and handlers that have timed out are automatically detached. - -## Comprehensive example - -Let us consider a practical use case of `Ctx`. The task is to download a file, we know the size of the file to download, we have an `Evt` that emits chunks of data, we want to accumulate them until we reach the expected file size. Multiple things can go wrong during the download: - -* The user can cancel the download. -* The download can take too long. -* Socket may disconnect . -* The socket may send more data than expected. - -Our expected output is a `Promise` that resolves with the downloaded file or reject if anything went wrong. - -This is a possible implementation using `Ctx`: - -```typescript -import { Evt, VoidEvt } from "evt"; - -function downloadFile( - { fileSize, evtChunk, evtBtnCancelClick, evtSocketError, timeout }: { - fileSize: number; - evtChunk: Evt; - evtBtnCancelClick: VoidEvt; - evtSocketError: Evt; - timeout: number; - } -): Promise { - - const ctxDl = Evt.newCtx(); - - evtSocketError.attachOnce( - ctxDl, - error => ctxDl.abort(error) - ); - - evtBtnCancelClick.attachOnce( - ctxDl, - () => ctxDl.abort(new Error("Download canceled")) - ); - - evtChunk - .pipe(ctxDl) - .pipe([ - (chunk, { byteLength, chunks }) => [{ - "byteLength": byteLength + chunk.length, - "chunks": [...chunks, chunk] - }], - { - "byteLength": 0, - "chunks": id([]) - } - ]) - .pipe(({ byteLength }) => byteLength >= fileSize) - .pipe(({ byteLength, chunks }) => byteLength !== fileSize ? - { "DETACH": ctxDl, "err": new Error("File is larger than expected") } : - [chunks] - ) - .pipe(chunks => [concatTypedArray(chunks, fileSize)]) - .attach(rawFile => ctxDl.done(rawFile)) - ; - - return ctxDl.waitFor(timeout); - -} -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-qpke6h?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -Whether the download is successful or not this use of Ctx enforce that there is no left over handlers on the Evt passed as input once the download attempt has completed. - diff --git a/docs/api/evt/README.md b/docs/api/evt/README.md deleted file mode 100644 index 5ae8ae41..00000000 --- a/docs/api/evt/README.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -description: >- - Evt is the Class that is the equivalent of EventEmitter in "events" and - Subject in "rxjs" ---- - -# Evt<T> - diff --git a/docs/api/evt/asnonpostable.md b/docs/api/evt/asnonpostable.md deleted file mode 100644 index 628a7f5c..00000000 --- a/docs/api/evt/asnonpostable.md +++ /dev/null @@ -1,35 +0,0 @@ -# Evt.asNonPostable\(evt\) - -{% hint style="info" %} -Evt.asNonPostable\(\) is the identity function with special type annotation -{% endhint %} - -Return the passed evt typed as an object that can't be posted. - -## Usecase: - -Take [this example](https://docs.evt.land/api/statefulevt#make-a-statefulevt-readonly). - -You could use this function to enforce that the return type by inferred and save you the trouble of having to import the `StatefulReadonlyEvt` interface: - -```typescript -import { Evt } from "evt"; - -//Return an event that post every second. -function generateEvtTick(delay: number) { - - const evtTick= Evt.create(0); - - setInterval(()=> evtTick.state++, delay); - - retrun Evt.asNonPostable(evtTick); - -} - -const evtTick= generateTick(1000); - - -evtTick.state++; // TS ERROR -evtTick.post(2); // TS ERROR -``` - diff --git a/docs/api/evt/aspostable.md b/docs/api/evt/aspostable.md deleted file mode 100644 index e300e63e..00000000 --- a/docs/api/evt/aspostable.md +++ /dev/null @@ -1,68 +0,0 @@ ---- -description: Cast the passed event as portable. ---- - -# Evt.asPostable\(evt\) - -{% hint style="info" %} -Evt.asNonPostable\(\) is the identity function with special type annotation -{% endhint %} - -{% hint style="warning" %} -Use this method only on`Evt` you instantiated yourself. Not as a hack to trigger events on `Evt` that have been exposed as non-postable by an API. -{% endhint %} - -To invoke `post()` on a `NonPostableEvt` or a `StatefullReadonlyEvt`. - -## Usecase: - -Without this method this would be the way for a class to expose `Evt` that are posted internally and exposed to be listened. - -```typescript -import { Evt } from "evt"; - -class Socket2 { - - private readonly _evtIsConnected= Evt.create(false); - private readonly _evtMessage= Evt.create(); - - readonly evtIsConnected= Evt.asNonPostable(this._evtIsConnected); - readonly evtMessage= Evt.asNonPostable(this._evtMessage); - - /* - OR, more explicit but require to repeat the types and to - import type { StatefulReadonlyEvt, NonPostableEvt } from "evt"; - - readonly evtIsConnected: StatefulReadonlyEvt= this._evtIsConnected; - readonly evtMessage: NonPostableEvt = this._evtMessage; - */ - - constructor(){ - - this._evtIsConnected.state = true; - this._evtMessage.post(new Uint8Array(111)); - - } - -} -``` - -Now it can be frustrating to have to store a private property only to call post on a object that we know is postable. Here is were this method come in handy: - -```typescript -class Socket { - - readonly evtIsConnected= Evt.asNonPostable(Evt.create(false)); - readonly evtMessage= Evt.asNonPostable(Evt.create()); - - constructor(){ - - Evt.asPostable(this.evtIsConnected).state = true; - Evt.asPostable(this.evtMessage).post(new Uint8Array(111)); - - } - - -} -``` - diff --git a/docs/api/evt/attach.md b/docs/api/evt/attach.md deleted file mode 100644 index 24df3dc9..00000000 --- a/docs/api/evt/attach.md +++ /dev/null @@ -1,103 +0,0 @@ ---- -description: Attach a Handler provided with a callback function to the Evt ---- - -# evt.\[$\]attach\*\(...\) - -There is multiple flavor of the attach method: `attachOnce`, `atachPrepend`, `attachExtract`... All this methods have in common to accept the same parameters and to return the same promise. - -## Returned Value - -It no timeout argument have been passed all attach methods return `this`. - -If a timeout arguement was passed a `Promise` that resolves with the first event data matched by the operator. By default of operator, all the events are matched. - -The returned promise can reject **only** if a timeout parameter was passed to the `attach*` method. - -If no event has been matched within the specified timeout, the promise will reject with a `EvtError.Timeout.` If the event is detached before the first event is matched, the promise will reject with an `EvtError.Detached`. - -If you have no use of the callback function and just want the promise, [`evt.waitFor(...)`](https://docs.ts-evt.dev/api-doc/evt#evt-waitfor) should be used in place of `evt.attach*(...)`. - -## Parameters - -1. `operator:` [`Operator`](https://docs.ts-evt.dev/api-doc/operator)`` -2. `timeout: number` Amount of time, in milliseconds before the returned promise rejects if no event has been matched within the specified delay. -3. `ctx:` [`Ctx`](https://docs.ts-evt.dev/api/ctx)A context that can be used as a reference to detach the handler later on. -4. `callback: (data: U)=> void` Function that will be invoked every time the matcher match an event emitted by the `Evt`. - -A large number of overload is provided to cover all the possible combination of arguments. The ordering in which the parameters are listed above must be respected but every parameter other than the callback can be omitted. - -![](../../.gitbook/assets/screenshot-2020-03-16-at-06.28.38%20%281%29.png) - -Examples: - -* Only specifying a timeout: `evt.attach(timeout, callback)` -* Specifying an operator and a context: `evt.attach(op, boundTo, callback)` -* ... - -## The `$` prefix - -Due to a current [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/36735) the `.attach*()` methods need to be prefixed with `$` when used with fλ operators but `evt.$attach*()` are actually just aliases to the corresponding `evt.attach*()` methods. - -## **`evt.[$]attach(...)`** - -Adds a new [handler](https://docs.ts-evt.dev/api/handler) to the end of the handlers array. No checks are made to see if the holder has already been added. Multiple calls passing the same combination of parameters will result in the `handler` being added, and called, multiple times. - -## **`evt.[$]attachOnce*(...)`** - -When the method contains the keyword "**once**": Adds a **one-time** [handler](https://docs.ts-evt.dev/api/handler). The next time an event is matched this handler is detached and then it's callback is invoked. - -## `evt.[$]attach[Once]Prepend(...)` - -When the method contains the keyword "**prepend**": Same as .attach\(\) but the [`handler`](https://docs.ts-evt.dev/api/handler) is added at the _beginning_ of the handler array. - -```typescript -import { Evt } from "evt"; - -const evtLetter = Evt.create(); - -evtLetter - .attach(() => console.log("B")) - .attach(() => console.log("C")) - .attachPrepend(() => console.log("A")) - ; - -evtLetter.post(); -//"A", "B", "C" is printed to the console. -``` - -[**Run the example**](https://stackblitz.com/edit/evt-qshmkh?embed=1&file=index.ts&hideExplorer=1) - -## **`evt.[$]attach[Once]Extract(...)`** - -When the method contains the "**extract**" keyword, every event that the [`handler`](https://docs.ts-evt.dev/api/handler) matches will be swallowed and no other handler will have the opportunity to handle it, even the other "extract"' handlers. It acts as a trap. - -"**extract**" handler has priority even over "**prepend**" [`Handler`](https://docs.ts-evt.dev/api/handler)s. - -If multiples "extractes" handlers are candidates to extract an event the handler that has been added first have priority. - -```typescript -import { Evt } from "evt"; - -const evtCircle = new Evt(); - -evtCircle.attachExtract( - ({ radius }) => radius <= 0, - ({ radius }) => console.log(`Circle with radius: ${radius} extracted`) -); - -evtCircle.attach( - circle => { - //We can assume that the circle has a positive radius. - console.assert(circle.radius > 0); - } -); - -//Extract have priority over prepend -evtCircle.attachPrepend( - circle => console.assert(circle.radius > 0) -); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-bwkprd?embed=1&file=index.ts&hideExplorer=1) - diff --git a/docs/api/evt/create.md b/docs/api/evt/create.md deleted file mode 100644 index 3902a724..00000000 --- a/docs/api/evt/create.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -description: Static method to instanciate an Evt or a StatefulEvt. ---- - -# Evt.create\(initalState?\) - -Evt.create\(\) is the prefered method for instantiating an Evt as this single method allow to instantiate Evt, StatefulEvt and VoidEvt. - -{% hint style="info" %} -The constructors are still useful however to avoid repeating the type of variable that are already typed e.g: `const evt: Evt = new Evt()` -{% endhint %} - -## Usage - -```typescript -import { Evt, VoidEvt, StatefulEvt } from "evt"; - -Evt.create() ⇔ new Evt() -Evt.create() ⇔ /* An object that implement VoidEvt */ -Evt.create(false) ⇔ new StatefulEvt(false) -``` - -## Why `VoidEvt` and not `Evt` ? - -When you instantiate an `Evt` with a void argument \( `new Evt()` \), TypeScript forces you to pass `undefined` to the post method \( it does not allows to call `evt.post()` \). -`VoidEvt` \( and respectively `VoidCtx` \) is a workaround for this annoyance. - -`VoidEvt` object are instances of `Evt` that you can post without passing argument. - -```typescript -import { Evt } from "evt"; - -const evtSocketConnect = Evt.create(); - -evtSocketConnect.attach(() => console.log("SOCKET CONNECTED")); - -evtSocketConnect.post(); -//"SOCKET CONNECTED" have been printed on the console. -``` - diff --git a/docs/api/evt/detach.md b/docs/api/evt/detach.md deleted file mode 100644 index 313f8764..00000000 --- a/docs/api/evt/detach.md +++ /dev/null @@ -1,67 +0,0 @@ ---- -description: Similar to EventEmitter.prototype.removeListener() ---- - -# evt.detach\(\[ctx\]\) - -Detach all handlers from the Evt or all Evt's handler that are bound to a given context. - -{% hint style="info" %} -The prefered way of detaching handler in TS-EVT is via [`Ctx`](https://docs.ts-evt.dev/api/ctx) . -{% endhint %} - -{% hint style="warning" %} -Calling this method without passing a context argument is almost never a good idea. An Evt instance should be sharable by modules that are isolated one another. If a module take the liberty to call evt.detach\(\) it can brek the code elswhere. -{% endhint %} - -{% hint style="info" %} -To chery pick the handlers to detach use [`evt.getHandlers()`](https://docs.ts-evt.dev/api/evt/evt.gethandler) or [`ctx.getHandlers()`](https://docs.ts-evt.dev/api/ctx#ctx-gethandlers)\`\` -{% endhint %} - -## Returns - -`Handler[]` array of Handler that have been detached. - -## Parameters - -`ctx?: Ctx` If [`Ctx`](https://docs.ts-evt.dev/api/ctx) is provided only Handler bound to the given context will be removed. - -## Examples - -To detach all handlers at once: - -```typescript -const evtText = new Evt(); -//detach with no argument will detach all handlers (attach, attachOnce, waitFor... ) -evtText.detach(); -``` - -Using a context argument - -```typescript -import { Evt } from "evt"; - -const evtText = new Evt(); - -evtText.attachOnce(text=> console.log(`Hello ${text}`)); - -const ctx = Evt.newCtx(); - -evtText.attach( - ctx, - _text => console.assert(false,"never") -); - -evtText.attachOnce( - ctx, - _text => console.assert(false,"never") -); - -evtText.detach(ctx); - -//"Hello World" will be printed -evtText.post("World"); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-bhxla6?embed=1&file=index.ts&hideExplorer=1) - diff --git a/docs/api/evt/enabletrace.md b/docs/api/evt/enabletrace.md deleted file mode 100644 index b7a283cf..00000000 --- a/docs/api/evt/enabletrace.md +++ /dev/null @@ -1,58 +0,0 @@ -# evt.enableTrace\(...\) - -If you need help to track down a bug, you can use `enableTrace` to log what's going on with an Evt. -Use `evt.disableTrace()` to stop logging. - -```typescript -import { Evt } from "evt"; - -{ - const evtCircle = new Evt(); - - evtCircle.enableTrace({ "id": "evtCircle n°1" }); - - evtCircle.post(circle1); - - evtCircle.attachOnce(circle => {}); - - evtCircle.post(circle2); - -} - -console.log("\n"); - -//Optional arguments -{ - - const evtCircle = new Evt(); - - evtCircle.enableTrace({ - "id": "evtCircle n°2", - "formatter": circle => `CIRCLE(${circle.radius})`, - "log": (...args)=> console.log(...["[myPrefix]",...args]) - // ^Log function default console log - ); - - evtCircle.attach( - ({ radius }) => radius > 15, - circle => {} - ); - - evtCircle.post(circle1); - evtCircle.post(circle2); - -} -``` - -This will print: - -```text -(evtCircle n°1) 0 handler, { "type": "CIRCLE", "radius": 12 } -(evtCircle n°1) 1 handler, { "type": "CIRCLE", "radius": 33 } - -[myPrefix] (evtCircle n°2) 0 handler, CIRCLE(12) -[myPrefix] (evtCircle n°2) 1 handler, CIRCLE(33) -``` - -[**Run the example**](https://stackblitz.com/edit/evt-vfjvfs?embed=1&file=index.ts&hideExplorer=1) - diff --git a/docs/api/evt/evtattachdetach.md b/docs/api/evt/evtattachdetach.md deleted file mode 100644 index 35997265..00000000 --- a/docs/api/evt/evtattachdetach.md +++ /dev/null @@ -1,28 +0,0 @@ -# evt.evt\[Attach\|Detach\] - -`evt.evtAttach` and `evt.evtDetach` are accessors for `Evt>` that posts every time a new handler is attached to/detached from the `Evt`. - -```typescript -import { Evt } from "evt"; - -const evtText= new Evt(); - -function myCallback(text: string){}; - -evtText.getEvtAttach().attach( - handler=> console.log(`${handler.callback.name} attached`) -); - -evtText.getEvtDetach().attach( - handler=> console.log(`${handler.callback.name} detached`) -); - -//"myCallback attached" is printed to the console. -evtText.attach(callback); - -//"myCallback detached" is printed to the console. -evtText.detach(); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-xwe67h?embed=1&file=index.ts&hideExplorer=1) - diff --git a/docs/api/evt/factorize.md b/docs/api/evt/factorize.md deleted file mode 100644 index 0424f4fe..00000000 --- a/docs/api/evt/factorize.md +++ /dev/null @@ -1,33 +0,0 @@ -# Evt.factorize\(evt\) - -{% hint style="info" %} -This is the identity function with special type annotations. -{% endhint %} - -If you have a variable that is either an `Evt` that post `A` or an `Evt` that post `B` you have an event that post `A or B`. - -In other words `Evt | Evt` is assignable to `Evt.` This method implement this proerty. - -```typescript -import { Evt, VoidEvt, matchVoid } from "evt"; - -declare evt: Evt | Evt | VoidEvt = Evt.create(); - -evt.attach(data=> { }); // TS ERROR - -Evt.factorize(evt) // OK, return Evt - .attach(data=> { // data is string | number | void - - //To test if data is void - if( matchVoid(data) ){ - return; - } - - //Here data is string | number. - - }) - ; -``` - -See also [`FactorizeEvt`](https://docs.evt.land/api/helpertypes#swapevttype-less-than-e-t-greater-than), helper type that this method levrage. - diff --git a/docs/api/evt/from.md b/docs/api/evt/from.md deleted file mode 100644 index 6e212a0d..00000000 --- a/docs/api/evt/from.md +++ /dev/null @@ -1,93 +0,0 @@ -# Evt.from<T>\(...\) - -Creates an Evt that post events of a specific type coming from other API that emmits events. - -## Returns - -Evt<T> will post every time the emitter emits - -## Parameters - -Ctx Optional, Allows detaching the handlers attached to the source emitter. - -`emitter`: Any of the following, - -* DOM EventTarget -* Node.js EventEmitter -* JQuery-like event target -* RxJS Subject -* An Array, NodeList or HTMLCollection of many of these. -* A promise - -Depending of the API the type argument will be inferred or not. - -`name`: The event name of interest, being emitted by the `target`. - -## Example - -### From `EventEmitter` - -```typescript -import { Evt } from "evt"; -import { EventEmitter } from "events"; - -const ctx= Evt.newCtx(); - -const ee= new EventEmitter(); -const evtText= Evt.from(ctx, ee, "text"); -evtText.attach(text=> console.log(text)); - -evtText.post("Foo bar");//Prints "Foo bar"; - -ctx.done(); - -console.log(ee.listenerCount("text"));//Prints "0" -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-qyk2ny?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -### With RxJS Subject - -```typescript -import { Evt } from "evt"; -import { Subject } from "rxjs"; - -const ctx= Evt.newCtx(); - -const subject = new Subject(); - -const evtText = Evt.from(ctx, subject); //The type argument is inferred. - -evtText.attach(text=> console.log(text)); - -subject.next("Foo bar"); //Prints "Foo bar" - -ctx.done(); - -subject.next("Foo bar"); //Prints nothing -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-t14cot?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -### With DOM EventTarget - -```typescript -import { Evt } from "evt"; - -Evt.from(document, "click").attach(()=> console.log("Clicked!")); -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-whhtbw?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -### With JQuery-like event target - -```typescript -import { Evt } from "evt"; - -Evt.from([ - $("#btnA"), - $("#btnB"), - $("#btnC") -], "click").attach(()=> console.log("Clicked!")); -``` - diff --git a/docs/api/evt/getctx.md b/docs/api/evt/getctx.md deleted file mode 100644 index 8e815847..00000000 --- a/docs/api/evt/getctx.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -description: A way to avoid having to create a ctx variable. ---- - -# Evt.getCtx\(object\) - -`Evt.weakCtx(obj)` always return the same instance of `VoidCtx` for a given object. - -No strong reference to the object is created when the object is no longer referenced it's associated Ctx will be freed from memory. - diff --git a/docs/api/evt/gethandler.md b/docs/api/evt/gethandler.md deleted file mode 100644 index 27209b4b..00000000 --- a/docs/api/evt/gethandler.md +++ /dev/null @@ -1,65 +0,0 @@ -# evt.getHandlers\(\) - -List all handlers attached to the `Evt`. Returns an array of [`Handler`](https://docs.ts-evt.dev/api/handler). - -Here a use case detaching all handlers that uses a given matcher: - -```typescript -import { Evt } from "evt"; - -const evtShape = new Evt(); - -evtShape.attach( - matchCircle, - circle => console.log("1:", circle) -); - -evtShape.attachOnce( - matchCircle, - circle => console.log("2:", circle) -); - -evtShape.waitFor(matchCircle) - .then(circle => console.log("3:", circle)) - ; - -//Only handler that does not use matchCircle as operator. -evtShape.attach(circle => console.log("4:", circle)) - - -evtShape.getHandlers() - .filter(({ op }) => op === matchCircle) - .forEach(({ detach }) => detach()) - ; - -//Prints only "4: ..." other handlers are detached. -evtShape.post({ "type": "CIRCLE", "radius": 300 }); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-zufivp?embed=1&file=index.ts&hideExplorer=1) - -`handler.detach(callback)` - -To detach all the handlers using a given callback function as we do with `EventEmitter`: - -```typescript -import { Evt } from "evt"; - -const evtText = new Evt(); - -const callback = (text: string) => console.log(text); - -evtText.attach(callback); - -evtText.post("Foo"); //Prints "Foo" - -evtText.getHandlers() - .filter(handler => handler.callback === callback) - .forEach(({detach})=> detach()) - ; - -evtText.post("Foo"); //Prints nothing -``` - -[**Run the example**](https://stackblitz.com/edit/evt-wrqoct?embed=1&file=index.ts&hideExplorer=1) - diff --git a/docs/api/evt/getstatelessop.md b/docs/api/evt/getstatelessop.md deleted file mode 100644 index ccc30450..00000000 --- a/docs/api/evt/getstatelessop.md +++ /dev/null @@ -1,72 +0,0 @@ -# evt.getStatelessOp\(op\) - -{% hint style="warning" %} -This is an advanced feature, it you are new to EVT you can skip this for now. -{% endhint %} - -It is not always possible to manually invoke an operator attached to an Handler that you got using `evt.getHandlers()`. Indeed if the operator is stateful you can't provide the `prev` value. This function gives access to this state. - -Because it is such an advanced feature we just provide an example as documentation: - -```typescript -//invokeOperator allow calling any type of stateless operator and -//get a return as if the operator was a fλ -import { Evt, invokeOperator } from “evt”; - - -{ - - const evtPoint = new Evt(); - - evtPoint.$attach( - [(point, sum) => [point + sum], 0], - sum => console.log(`sum: ${sum}`) - ); - - evtPoint.post(2); // Prints "sum: 2" - - console.log( - invokeOperator( - evtPoint.getStatelessOp( - evtPoint.getHandlers()[0].op - ), - 2 - ) - ); // Prints "[ 4 ]" ( 2 + 2 ) - - evtPoint.post(3); // Prints "sum: 5" ( the state was not affected ) - -} - -{ - - const evtPoint = new Evt(); - - evtPoint.attach( - point => point > 10, - point => { } - ); - - console.log( - invokeOperator( - evtPoint.getStatelessOp( - evtPoint.getHandlers()[0].op - ), - 5 - ) - ); // Prints "null" ( 5 < 10 ) - - console.log( - invokeOperator( - evtPoint.getStatelessOp( - evtPoint.getHandlers()[0].op - ), - 15 - ) - ); // Prints "[ 15 ]" ( 15 > 10 ) - -} -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-yljxhq?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - diff --git a/docs/api/evt/ishandled.md b/docs/api/evt/ishandled.md deleted file mode 100644 index 77fc071d..00000000 --- a/docs/api/evt/ishandled.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -Description: Test if posting event data will have an effect. ---- - -# evt.isHandled\(data\) - -Return true if: - -* There is at least one handler matching this event data \( at least one handler's callback function will be invoked if the data is posted. \) -* There is at least one handler that will be detached if the event data is posted. - -```typescript -const evtText = new Evt(); - -/* -Handle the text starting with 'h'. -Ignore all other text, when a text starting with 'g' -is posted the handler is detached -*/ -evtText.$attach( - text=> text.startsWith("h") ? - [ text ] : - text.startsWith("g") ? "DETACH" : null, - text=> {/* do something with the text */} -); - -//"true", start with 'h' -console.log( - evtText.isHandled("hello world") -); - -//"false", do not start with 'h' or 'g' -console.log( - evtText.isHandled("foo bar") -); - -//"true", not matched but will cause the handler to be detached if posted -console.log( - evtText.isHandled("goodby world") -); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-a3m4od?embed=1&file=index.ts&hideExplorer=1) - diff --git a/docs/api/evt/loosentype.md b/docs/api/evt/loosentype.md deleted file mode 100644 index fc5d826c..00000000 --- a/docs/api/evt/loosentype.md +++ /dev/null @@ -1,22 +0,0 @@ -# Evt.loosenType\(evt\) - -{% hint style="info" %} -This is the identity function with special type annotations. -{% endhint %} - -Swipe the type argument with a superset without giving up type safety. - -If `A` is assignable to `B` ⇒ `Evt` is assignable to `Evt` - -e.g:`Evt<1|2|3>` is assignable to `Evt` however typescript wont let you do this assignation. This is where `Evt.loosenType` come in handy. - -```typescript -import { Evt } from "evt"; - -declare const evFooBar: Evt<"FOO" | "BAR">; -declare function myFunc(evtText: Evt): void; - -myFunc(evtFooBar); //Gives a type error; -myFunc(Evt.loosenType(evtFooBar)); //OK -``` - diff --git a/docs/api/evt/merge.md b/docs/api/evt/merge.md deleted file mode 100644 index fba98d65..00000000 --- a/docs/api/evt/merge.md +++ /dev/null @@ -1,38 +0,0 @@ -# Evt.merge\(\[ evt1, evt2, ... \]\) - -Returns a new `Evt` instance which concurrently post all event data from every given input `Evt`. - -## Return - -A new Evt that has for type arguments the union of the type arguments of the inputs Evt. - -## Parameters - -Ctx<any> Optional, Ctx that will be used to detach the handler that has been attached to the input Evts. - -Evt<any>\[\] Evts to be merged. - -## Example - -```typescript -import { Evt } from "evt"; - -const ctx= Evt.newCtx(); - -const evtText = new Evt(); -const evtTime = new Evt(); - -//evtTextOrTime is Evt -const evtTextOrTime= Evt.merge(ctx, [evtText, evtTime]); - -evtTextOrTime.attach(console.log); - -evtText.post("Foo bar"); //Prints "Foo bar" - -ctx.done(); - -evtText.post("Foo bar"); //Prints nothing -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-nbshnc?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - diff --git a/docs/api/evt/newctx.md b/docs/api/evt/newctx.md deleted file mode 100644 index a482bc2c..00000000 --- a/docs/api/evt/newctx.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -description: Get a new instance of Ctx ---- - -# Evt.newCtx<T>\(\) - -The recommended way to get a new [`Ctx`](https://docs.ts-evt.dev/api/ctx) instance. The type argument is optional, default is void. - -## Returns - -* [`Ctx`](https://docs.ts-evt.dev/api/ctx) if a type argument was specified -* [`VoidCtx`](https://docs.ts-evt.dev/api/ctx) if no type argument was speficied. - -## Example - -```typescript -import { Evt } from "evt"; - -const ctx = Evt.newCtx(); - -ctx.getPrDone().then(()=> console.log("DONE")); - -ctx.done(); //Prints "DONE" - -//---------------------------- - -const ctxData = Evt.newCtx(); - -ctxText.getPrDone().then( - data=> console.log(`DONE: ${data.byteLength} bytes`) -); - -ctxText.done(new Uint8Array([1,2,3])); //Prints "DONE: 3 bytes" -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-5xs5rr?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - diff --git a/docs/api/evt/pipe.md b/docs/api/evt/pipe.md deleted file mode 100644 index 88a83fbb..00000000 --- a/docs/api/evt/pipe.md +++ /dev/null @@ -1,128 +0,0 @@ ---- -description: An alternative to compose for chaining operaors. ---- - -# evt.pipe\(...\) - -{% hint style="warning" %} -Being familiar with [`Ctx`](https://docs.evt.land/api/ctx) and [`Operator`](https://docs.evt.land/api/operator)is a prerequisite for properly using pipe. -{% endhint %} - -## Return - -A new Evt instance toward which are forwarded the transformed events matched by the operator\(s\). - -## Parameters - -`Ctx`: Optional, the context to which will be bound the handler responsible for forwarding events to the returned Evt. - -`...Operator[]`: One or many operators composable with one another. - -## Examples - -There are two ways of using pipe, the first is to call pipe only once and passing it all the operators to chain, the second is to chain the `pipe` calls providing each time a single operator. Depending on the situation, you should favor one approach over the other. - -Let us consider a case where the two approaches are equally valid. - -Using a single call to `pipe`: - -```typescript -import { Evt } from "evt"; - -type Circle = { type: "CIRCLE"; radius: number; }; -type Square = { type: "SQUARE"; sideLength: number; }; -type Shape = Circle | Square; - -const evtShape = new Evt(); - -evtShape.pipe( - shape => !shape ? null : [ shape ], // Filter out undefined - shape => shape.type !== "CIRCLE" ? null : [ shape ], // Filter Circle - ({ radius }) => [ radius ], // Extract radius - radius => radius > 200 ? "DETACH": [ radius ] //Detach if radius too large -).attach(radius=> { /* ... */ }); -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-jx2nnm?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -Same thing chaining `pipe`: - -```typescript -const evtShape = new Evt(); - -const ctx= Evt.newCtx(); - -evtShape - .pipe(ctx) - .pipe(shape => !shape ? null : [ shape ]) - .pipe(shape => shape.type !== "CIRCLE" ? null : [ shape ]) - .pipe(({ radius }) => [ radius ]) - .pipe(radius => radius > 200 ? { "DETACH": ctx } : [radius]) - .attach(radius => { /* ... */ }); -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-yb4gzb?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -{% hint style="danger" %} -When chaining `pipe` if one operator in the midle of the chain returns `"DETACH"` all the handler upstream will stay attached. You must always detach the first link of the chain using a [`Ctx`](https://docs.evt.land/api/ctx). -{% endhint %} - -The first approach \(calling pipe only once\) is preferable as it is slightly less verbose but in some cases you will reach the limits of TypeScript inference capabilities especially if you throw filters and generic operators into the mix. Bottom point is: try the first method, see how TypeScript infer the types, if detection fails fallback to chainging `pipe()`. - -### Creating delegates - -Pipe can also be used to create proxies to a source `Evt`. - -```typescript -import { Evt } from "evt"; - -const evtShape = new Evt(); - -//evtCircle is of type Evt because matchCircle is a type guard. -const evtCircle = evtShape.pipe(matchCircle); - -//evtLargeShape is of type Evt -const evtLargeShape = evtShape.pipe(shape => { - switch (shape.type) { - case "CIRCLE": - return shape.radius > 5; - case "SQUARE": - return shape.sideLength > 3; - } -}); - -evtCircle.attach(({ radius }) => - console.log(`Got a circle, radius: ${radius}`) -); - -evtLargeShape.attach( - shape => console.log(`Got a large ${shape.type}`) -); - -//"Got a circle, radius: 66" and "Got a large CIRCLE" will be printed. -evtShape.post({ - "type": "CIRCLE", - "radius": 66 -}); - -//Only "Got a circle, radius: 3" will be printed -evtShape.post({ - "type": "CIRCLE", - "radius": 3 -}); - -//Only "Got a large SQUARE" will be printed -evtShape.post({ - "type": "SQUARE", - "sideLength": 30 -}); - -//Nothing will be printed -evtShape.post({ - "type": "SQUARE", - "sideLength": 1 -}); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-e9zjnq?embed=1&file=index.ts&hideExplorer=1) - diff --git a/docs/api/evt/post.md b/docs/api/evt/post.md deleted file mode 100644 index 105300e4..00000000 --- a/docs/api/evt/post.md +++ /dev/null @@ -1,74 +0,0 @@ -# evt.post\*\(data\) - -## **`evt.post(data)`** - -Equivalent of `eventEmitter.emit()` and `subject.next()`. - -Returns evt.postCount - -## **`evt.postCount: number`** - -The number of times `evt.post()` has been called. It's a read-only property. - -```typescript -import { Evt } from "evt"; - -const evtText= new Evt(); - -//prints 0 -console.log(evtText.postCount); - -evtText.post("foo"); -evtText.post("bar"); -evtText.post("baz"); - -//prints 3 -console.log(evtText.postCount); -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-2npimn?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -## `evt.postAsyncOnceHandled(data)` - -Post the event data only once there is at least one handler candidate to handle it. - -When `evt.isHandled(data)` return `true`, `post(data)` is invoked synchronously and the new post count is returned. When `postAsyncOnceHandled(data)` is invoked at a time where`evt.isHandled(data)` returns `false`, the `data` will be kept on hold and posted only once a candidate handler is attached. - -`evt.post(data)` is not invoked synchronously as soon as the candidate handler is attached but is scheduled to be invoked in a microtask. -When the call to post is delayed `postAsyncOnceHandled(data)` returns a promise that resolves with the new post count after `post(data)` has been invoked. - -```typescript -import { Evt } from "evt"; - -function createPreloadedEvtText(): Evt{ - - const evtText = new Evt(); - - (async ()=>{ - - await evtText.postAsyncOnceHandled("foo"); - evtText.post("bar"); - - })(); - - - return evtText; - -} - -const evtText = createPreloadedEvtText(); - -evtText.attach(text => console.log("1 " + text)); -evtText.attach(text => console.log("2 " + text)); - -console.log("BEFORE"); - -//"BEFORE" then (next micro task) "1 foo" "2 foo" "1 bar" "2 bar" -``` - -[**Run the example**](https://stackblitz.com/edit/evt-mycz4t?embed=1&file=index.ts&hideExplorer=1) - -{% hint style="info" %} -`evt.postSyncOnceHandled()` does not exist because it is preferable to wait for the next event cycle before posting the event. For example, the previous example would not print `"2 foo"` if we had used `evt.postSyncOnceHandled()` -{% endhint %} - diff --git a/docs/api/evt/setdefaultmaxhandlers.md b/docs/api/evt/setdefaultmaxhandlers.md deleted file mode 100644 index b5f8800d..00000000 --- a/docs/api/evt/setdefaultmaxhandlers.md +++ /dev/null @@ -1,12 +0,0 @@ -# Evt.setDefaultMaxHandlers\(n\) - -By default if an `Evt` is attached more than 25 handlers a warning will be displayed. It is possible to increase this limmit on a specific `Evt` instance using [`evt.setMaxHandlers(n)`](https://docs.evt.land/api/evt/setmaxhandlers) or globally with this static method. - -Using this method will not overwrite the vale set on specific instance with `evt.setMaxHandlers(n)`. - -Use Infinity or 0 to completely disable the warning. - -{% hint style="warning" %} -Different version of EVT can be coabitating in a single project. The modification will only apply to the `Evt`s instantiated by this constructor. -{% endhint %} - diff --git a/docs/api/evt/setmaxhandlers.md b/docs/api/evt/setmaxhandlers.md deleted file mode 100644 index 4cb2a72c..00000000 --- a/docs/api/evt/setmaxhandlers.md +++ /dev/null @@ -1,8 +0,0 @@ -# evt.setMaxHandlers\(n\) - -By default `Evt` will print a warning if more than 25 handlers are added. This is a useful default that helps finding memory leaks. Not all events should be limited to 25 handlers. The `evt.setMaxHandlers()` method allows the limit to be modified for this specific `Evt` instance. \( Use the static method [`Evt.setDefaultMaxHandlers()`](https://docs.evt.land/api/evt/setdefaultmaxhandlers) to change this limit globally. - -The value can be set to `Infinity` \(or 0\) to indicate an unlimited number of listeners. - -Returns a reference to the Evt, so that calls can be chained. - diff --git a/docs/api/evt/tostateful.md b/docs/api/evt/tostateful.md deleted file mode 100644 index 4f379d9b..00000000 --- a/docs/api/evt/tostateful.md +++ /dev/null @@ -1,4 +0,0 @@ -# toStateful\(initialState\) - -See [StatefulEvt<T>](https://docs.evt.land/api/statefulevt#converting-an-evt-into-a-statefulevt) - diff --git a/docs/api/evt/use-effect.md b/docs/api/evt/use-effect.md deleted file mode 100644 index 740151cb..00000000 --- a/docs/api/evt/use-effect.md +++ /dev/null @@ -1,57 +0,0 @@ -# Evt.useEffect\(...\) - -Invoke a callback now and every time an event is posted. If the event passed is statefull the effect callback is only invoked when `evtChange` is posted. - -```typescript -import { Evt } from "evt"; - -const evtText = new Evt(); -const evtAge = new Evt(); - -const ctx = Evt.newCtx(); - -//Prints [ undefined, { "isFirst": true }, 0] -Evt.useEffect( - (...args) => console.log(args), - Evt.merge( - ctx, - [ - evtText, - evtAge - ] - ) -); - -//Prints [ "Foo Bar", { "isFirst": false, data: "Foo Bar" }, 1] -evtText.post("Foo Bar"); - -//Prints [ 99, { "isFirst": false, data: 99 }, 2 ] -evtAge.post(99); - -ctx.done(); - -//Prints nothing, Evt detached. -evtAge.pose(1); -``` - -Used with [`StatefulEvt`](https://docs.evt.land/api/statefulevt)s: - -```typescript -import { Evt } from "evt"; - -const evtText = Evt.create("foo"); - - -Evt.useEffect( - text=> console.log(text), - evtText.evtChange.pipe(ctx) -); // Pints "foo" - -evtText.state= "bar"; // Prints "bar" -evtText.state= "bar"; // Prints nothing - -ctx.done(); - -evtText.state= "baz"; // Prints nothing -``` - diff --git a/docs/api/evt/waitfor.md b/docs/api/evt/waitfor.md deleted file mode 100644 index d127c91f..00000000 --- a/docs/api/evt/waitfor.md +++ /dev/null @@ -1,105 +0,0 @@ -# evt.waitFor\(...\) - -Method that returns a promise that will resolve when the next matched event is posted. - -waitFor is essentially evt.attachOnce\(...\) but you don’t provide a callback. It accepts the same arguments and return the same promise. - -_Essentialy_ the same but [not exactly the same](https://docs.ts-evt.dev/api/evt/evt.waitfor-...#difference-between-evt-waitfor-and-evt-attachonce), there is a key difference between a handler attached via `waitFor` and a handler attached with `attach*` as explained below. - -## Without timeout - -By default the promise returned by `waitFor` will never reject. - -```typescript -import { Evt } from "evt"; - -const evtText = new Evt(); - -setTimeout(()=> evtText.post("Hi!"), 1500); - -(async ()=>{ - - //waitFor return a promise that will resolve next time - //post() is invoked on evtText. - const text = await evtText.waitFor(); - - console.log(text); - -})(); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-cazqyr?embed=1&file=index.ts&hideExplorer=1) - -## With timeout - -As with `attach*`, it is possible to set what is the maximum amount of time we are willing to wait for the event before the promise rejects. - -```typescript -import { Evt, EvtError } from "evt"; - -const evtText = new Evt(); - -(async ()=>{ - - try{ - - const text = await evtText.waitFor(500); - - console.log(text); - - }catch(error){ - - console.assert(error instanceof EvtError.Timeout); - //Error can be of two type: - // -EvtError.Timeout if the timeout delay was reached. - // -EvtError.Detached if the handler was detached before - // the promise returned by waitFor have resolved. - - console.log("TIMEOUT!"); - - } - -})(); - -//A random integer between 0 and 1000 -const timeout= ~~(Math.random() * 1000); - -//There is a fifty-fifty chance "Hi!" is printed else it will be "TIMEOUT!". -setTimeout( - ()=> evtText.post("Hi!"), - timeout -); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-wqh856?embed=1&file=index.ts&hideExplorer=1) - -## Difference between `evt.waitFor(...)` and `evt.attachOnce(...)` - -`const pr= evt.waitFor()` is **NOT** equivalent to const `pr= evt.attachOnce(()=>{})` - -`evt.waitFor()` is designed in a way that makes it safe to use `async` procedures. - -Basically it means that the following example prints `A B` on the console instead of waiting forever for the secondLetter. - -```typescript -import { Evt } from "evt"; - -const evtText = new Evt(); - -(async ()=>{ - - const firstLetter = await evtText.waitFor(); - const secondLetter = await evtText.waitFor(); - - console.log(`${firstLetter} ${secondLetter}`); - -})(); - -evtText.post("A"); -evtText.post("B"); - -//"A B" is printed to the console. -``` - -Run this [**more practical example**](https://stackblitz.com/edit/evt-v4q4s2?embed=1&file=index.ts&hideExplorer=1) if you want to understand how this behavior prevent from some hard to figure out bugs. - diff --git a/docs/api/handler.md b/docs/api/handler.md deleted file mode 100644 index c4e0eabf..00000000 --- a/docs/api/handler.md +++ /dev/null @@ -1,56 +0,0 @@ -# Handler<T, U> \(type\) - -Every time [`attach*`](https://docs.ts-evt.dev/api/evt/evt.attach), [`waitFor`](https://docs.evt.land/api/evt/waitfor) or [`pipe`](https://docs.evt.land/api/evt/pipe) is invoked a new [`Handler`](https://docs.evt.land/api/handler) is attached to the [`Evt`](https://docs.evt.land/api/evt). - -Handlers can be listed using the [`evt.getHandler()`](https://docs.evt.land/api/evt/evt.gethandler) method. - -```typescript -type Handler = { - - //Method for detaching the handler from the Evt, returns false if - //if invoked when the handler is no longer attached. - detach(): boolean; - - //The promise returned by the attach*() and waitFor() method. - promise: Promise; - - - /* Properties that depends on the method used to attach the handler */ - - //true if the handler was attached using a method containing "prepend" - //in it's name. Example: evt.$attachOncePrepend(...) - prepend: boolean; - - //... if the method contained "extract" - extract: boolean; - - //... if the method contained "once" - once: boolean; - - //if the method was waitFor() - async: boolean; - - - - /* Properties passed as argument to the method used to attach the handler */ - - //Default: ()=> true, a filter that matches all events. - op: Operator; - - //Default: undefined - ctx?: Ctx; - - //Default: undefined. - timeout?: number; - - //Undefined only when the handler was attached using evt.waitFor() - callback?: (transformedData: U)=> void; - -}; -``` - -## Glossary relative to handers: - -* An event is said to be **matched** by a handler if posting it causes the callback to be invoked. In practice this is the case when the handler's operator returns true or \[ value, \]. -* An event is said to be **handled** by a handler if the event data is matched or if posting it causes the handler and/or other potential handlers to be detached. In practice this is the case when the handler's operator returns `"DETACH"` or `{DETACH: Ctx}.` It is possible to test if a given event data is handled by at least one of the handlers attached to an Evt<T> by using the [`evt.isHandled(data)`](https://docs.ts-evt.dev/api/evt/evt.ishandled) method. - diff --git a/docs/api/helpertypes.md b/docs/api/helpertypes.md deleted file mode 100644 index a6af0805..00000000 --- a/docs/api/helpertypes.md +++ /dev/null @@ -1,149 +0,0 @@ -# Helper types - -## ToNonPostableEvt<E> - -{% hint style="info" %} -`NonPostableEvt` and `StatefulReadonlyEvt` are interfaces implemented respectively by the classes `Evt` and `StatefulEvt`. They contains all the methods but the ones used to post events, namely: `.post(), .postOnceHandled()` and the `.state` setter for `StatefulReadonlyEvt` -{% endhint %} - -```typescript -import { ToNonPostableEvt } from "evt"; - -ToNonPostableEvt> → NonPostableEvt -ToNonPostableEvt> → StatefulReadonlyEvt -ToNonPostable → NonPostable -ToNonPostable> → NonPostableEvt - -ToNonPostableEvt<{ - evtText: Evt; - evtCount: StatefulEvt; - type: "FOO" -}> - → -{ - evtText: NonPostableEvt; - evtCount: StatefulNonpostableEvt; - type: "FOO" -} -``` - -Example use of the `NonPostableEvt` interface: - -```typescript -import { Evt, NonPostableEvt } from "evt"; - -const evtText= new Evt(); - -//Api to expose. -export const api:{ evtText: NonPostableEvt; } = { evtText }; - -//evtText exposed by the api cannot be posted… -api.evtText.post //<=== TS error -api.evtText.postOnceMatched //<===== TS error - -//…but we can post internally. -evtText.post("good"); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-xc2eqj?embed=1&file=index.ts&hideExplorer=1) - -## **ToPostableEvt<E>** - -Invert of `ToNonPostableEvt` - -```typescript -import { - ToPostableEvt, - NonPostableEvt, - StatefulReadonlyEvt -} from "evt"; - -ToPostableEvt> → Evt -ToPostableEvt> → StatefulEvt -ToPostable> → VoidEvt -ToPostable> → Evt - -ToPostableEvt<{ - evtText: NonPostableEvt; - evtCount: StatefulReadonlyEvt; - type: "FOO" -}> - → -{ - evtText: Evt; - evtCount: StatefulEvt; - type: "FOO" -} -``` - -## UnpackEvt<E> - -Extract the type argument of an Evt - -```typescript -import { UnpackEvt } from "evt"; - -UnpackEvt> → number -UnpackEvt> → number -UnpackEvt> → number - -UnpackEvt<{ - evtText: Evt; - evtCount: StatefulEvt; - type: "FOO" -}> - → -{ - evtText: string; - evtCount: number; - type: "FOO" -} -``` - -### Example: - -UnpackEvt is a helper type to infer the type argument of an Evt instance. - -```typescript -import { Evt, UnpackEvt } from "evt"; - -const evtHuman = new Evt<{ - name: string; - age: number; - gender: "MALE" | "FEMALE" -}>(); - - -type Human = UnpackEvt; - -const human: Human = { - "name": "bob", - "age": 89, - "gender": "MALE" -}; - -evtHuman.post(human); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-ykjacd?embed=1&file=index.ts&hideExplorer=1) - -## SwapEvtType<E, T> - -```typescript -import { SwapEvtType } from "evt"; - -SwapEvtType, number> → Evt -SwapEvtType, number> → SatefulEvt -SwapEvtType, void> → VoidEvt -SwapEvtType, void> → VoidEvt -``` - -## FactorizeEvt<E> - -```typescript -import { FactorizeEvt } from "evt"; - -FactorizeEvt | Evt> → Evt -//...Work as well with StatefulEvt, NonPostable ect -``` - diff --git a/docs/api/operator.md b/docs/api/operator.md deleted file mode 100644 index a9a25d59..00000000 --- a/docs/api/operator.md +++ /dev/null @@ -1,601 +0,0 @@ ---- -description: >- - Operators provide a way to transform events data before they are passed to the - callback. ---- - -# Operator<T, U> \(type\) - -EVT Operators can be of three types: - -* **Filter**: `(data: T)=> boolean`. - - Only the matched event data will be passed to the callback. - -* **Type guard**: `(data: T)=> data is U` - - Functionally equivalent to filter but restrict the event data type. - -* **fλ** - - Filter / transform / detach handlers - - * **Stateless fλ**: `(data: T)=> [U] | null | "DETACH" | {DETACH:`[`Ctx`](https://docs.ts-evt.dev/api/ctx)`} |...` - * **Stateful fλ**: `[ (data: T, prev: U)=> ..., U ]` - - Uses the previous matched event data transformation as input à la `Array.prototype.reduce` - -{% hint style="warning" %} -Operators do not have to be [pure](https://en.wikipedia.org/wiki/Pure_function), they can use variables available in scope and involve time `(Date.now())`, but they **must not have any side effect**. In particular they cannot modify their input. -{% endhint %} - -## Operator - Filter - -Let us consider the example use of an operator that filters out every word that does not start with 'H'. - -```typescript -import { Evt } from "evt"; - -const evtText= Evt.create(); - -evtText.attach( - text=> text.startsWith("H"), - text=> { - console.assert( text.startsWith("H") ); - console.log(text); - } -); - -//Nothing will be printed to the console. -evtText.post("Bonjour"); - -//"Hi!" will be printed to the console. -evtText.post("Hi!"); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-38z5nd?embed=1&file=index.ts&hideExplorer=1) - -It is important to be sure that your filter always return a `boolean`, typewise you will be warned it is not the case but you must be sure that it is actually the case at runtime. -If in doubts use 'bang bang' \( `!!returnedValue` \). This note also applies for [Type Gard operators](https://docs.evt.land/api/operator#operator-type-guard). - -## Operator - Type guard - -If you use a filter that is also a [type guard](https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards), the type of the callback argument will be narrowed down to the matched type. - -Let us define a straight forward type hierarchy to illustrate this feature. - -```typescript -type Circle = { - type: "CIRCLE"; - radius: number; -}; - -type Square = { - type: "SQUARE"; - sideLength: number; -}; - -type Shape = Circle | Square; - -//Type Guard for Circle: -const matchCircle = (shape: Shape): shape is Circle => - shape.type === "CIRCLE"; -``` - -The `matchCircle` type guard can be used to attach a callback to an `Evt` that will only be called against circles. - -```typescript -import { Evt } from "evt"; - -const evtShape = Evt.create(); - -evtShape.attach( - matchCircle, - shape => console.log(shape.radius) -); - -//Nothing will be printed on the console, a Square is not a Circle. -evtShape.post({ "type": "SQUARE", "sideLength": 3 }); - -//"33" Will be printed to the console. -evtShape.post({ "type": "CIRCLE", "radius": 33 }); -``` - -The type of the Shape object is narrowed down to `Circle` -![Screenshot 2020-02-08 at 19 17 46](https://user-images.githubusercontent.com/6702424/74090059-baab3e00-4aa7-11ea-9c75-97f1fb99666d.png) - -[**Run the example**](https://stackblitz.com/edit/evt-nn29kf?embed=1&file=index.ts&hideExplorer=1) - -## Operator - fλ - -Anonymous functions to simultaneously filter, transform the data and control the event flow. - -**fλ Returns** - -The type of values that a fλ operator sole determine what it does: - -* `null` If the event should be ignored and nothing passed to the callback. -* `[ U ]` or `[ U, null ]` When the event should be handled, wrapped into the singleton is the value will be passed to the callback. -* `"DETACH"` If the event should be ignored and the handler detached from the `Evt` -* `{ DETACH: Ctx }` If the event should be ignored and a group of handlers bound to a certain context be detached. See [`Ctx`](https://docs.ts-evt.dev/api/ctx) -* `{ DETACH: Ctx, res: V }` See [`Ctx`](https://docs.ts-evt.dev/api/ctx)\`\` -* `{ DETACH: Ctx; err: Error }` See [`Ctx`](https://docs.ts-evt.dev/api/ctx)\`\` -* `[ U, "DETACH" ]` / `[ U, {DETACH:Ctx, ...} ]` If the event should be handled AND some detach be performed. - -### **Stateless fλ** - -Stateless fλ operator only takes the event data as arguments. - -```typescript -import { Evt } from "evt"; - -const evtShape = Evt.create(); - -/* - * Filter: - * Only circle events are handled. - * AND - * to be handled circles must have a radius greater than 100 - * - * Transform: - * Pass the radius of such circles to the callback. - */ -evtShape.$attach( - shape => shape.type === "CIRCLE" && shape.radius > 100 ? - [ shape.radius ] : null, - radiusOfBigCircle => console.log(`radius: ${radius}`) - //NOTE: The radius argument is inferred as being of type number! -); - -//Nothing will be printed to the console, it's not a circle -evtShape.post({ "type": "SQUARE", "sideLength": 3 }); - -//Nothing will be printed to the console, The circle is too small. -evtShape.post({ "type": "CIRCLE", "radius": 3 }); - -//"radius 200" Will be printed to the console. -evtShape.post({ "type": "CIRCLE", "radius": 200 }); -``` - -Other example using `"DETACH"` - -```typescript -import { Evt } from "evt"; - -const evtText= Evt.create<"TICK" | "END">(); - -/* - * Only handle events that are not "END". - * If the event is "END", detach the handler. - * Pass the event data string in lower case to the callback. - */ -evtText.$attach( - text => text !== "END" ? [ text.toLowerCase() ] : "DETACH", - text => console.log(text) -); - -evtText.post("TICK"); //"tick" is printed to the console -evtText.post("END"); //Nothing is printed on the console, the handler is detached -evtText.post("TICK"); //Nothing is printed to the console. -``` - -Example use of `[U,null|"DETACH"]`, handling the event that causes the handler to be detached. - -```typescript -const evtText= Evt.create<"TICK" | "END">(); - -evtText.$attach( - text => [ text, text === "END" ? "DETACH" : null ], - text => console.log(text) -); - -evtText.post("TICK"); //"TICK" is printed to the console -evtText.post("END"); //"END" is printed on the console, the handler is detached. -evtText.post("TICK"); //Nothing is printed to the console the handler has been detached. -``` - -Example use of `{ DETACH:`[`Ctx`](https://docs.ts-evt.dev/api-doc/ctx)`}`, detaching a group of handlers bound to a given context. - -```typescript -const evtBtnClick = Evt.create<"OK" | "QUIT">(); - -const evtMessage = Evt.create(); -const evtNotification = Evt.create(); - -const ctx= Evt.newCtx(); - -evtMessage.attach( - ctx, - message => console.log(`message: ${message}`) -); - -evtNotification.attach( - ctx, - notification => console.log(`notification: ${notification}`) -); - -evtBtnClick.$attach( - type => [ - type, - type !== "QUIT" ? null : { "DETACH": ctx } - ], - type => console.log(`Button clicked: ${type}`) -); - -evtBtnClick.post("OK"); //Prints "Button clicked: OK" -evtMessage.post("Hello World"); //Prints "Message: Hello World" -evtNotification.post("Poke"); //Prints "Notification: Poke" -evtBtnClick.post("QUIT"); //Prints "Button clicked: QUIT", handlers are detached... -evtMessage.post("Hello World 2"); //Prints nothing -evtNotification.post("Poke 2"); //Prints nothing -evtBtnClick.post("OK"); //Prints "Button clicked: OK", evtBtnClick handler hasn't been detached as it was not bound to ctx. -``` - -[**Run examples**](https://stackblitz.com/edit/evt-mf3nzt?embed=1&file=index.ts&hideExplorer=1) - -### **Stateful fλ** - -The result of the previously matched event is passed as argument to the operator. - -```typescript -import { Evt } from "evt"; - -const evtText= Evt.create(); - -evtText.$attach( - [ - (str, prev)=> [`${prev} ${str}`], - "START: " //<= seed - ], - sentence => console.log(sentence) -); - -evtText.post("Hello"); //Prints "START: Hello" -evtText.post("World"); //Prints "START: Hello World" -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/ts-evt-demo-stateful-qs1nsh?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -### Dos and don'ts - -Operators cannot have any side effect \(they cannot modify anything\). No assumption should be made on when and how they are called. - -#### Don't encapsulate state, do use stateful **fλ** - -The first thing that you might be tempted to do is to use a variable available in the operator's scope as an accumulator. - -The following example **seems equivalent from the previous one** but it is **not**. - -```typescript -const evtText= Evt.create(); - -//🚨 DO NOT do that 🚨... -evtText.$attach( - (()=> { - - let acc= "START:"; - - return (data: string) => [acc += ` ${data}`] as const; - - })(), - sentence => console.log(sentence) -); - -const text= "Foo bar"; - -if( evtText.isHandled(text) ){ - //Prints "START: Foo Bar Foo bar", probably not what you wanted... - evtText.post(text); -} -``` - -When evt.isHandled\(data\) is invoked the operator of every handler is invoked. The operator is invoked again when the event is actually posted. - -In the example every time the operator is invoked the encapsulated variable acc is updated. This result in "Foo bar" being accumulated twice when the event is posted only once. - -`evt.postAsyncOnceHandled(data)` will also cause dry invokations of the operators. - -If state is needed stat full fλ have to be used. - -#### Don't modify input, do return a copy. - -```typescript -import { Evt } from "evt"; - -const evtText= Evt.create(); - -//Do not modify the accumulator value. -evtText.$attach( - [ - (text, arr: string[])=> { - arr.push(text); - return [arr]; - }, - [] - ], - arr=> { /*...*/ } -); - -/* ----------------------------- */ - -//Do Return a new array -evtText.$attach( - [ - (text, arr: string[]) => [[...arr, text]], - [] - ], - arr=> { /*...*/ } -); -``` - -#### Do use const assertions \( `as const` \) - -The TypeScript [const assertion features](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) come in handy if you introduce closures, for example. The following example does not compile without the use of `as const`. - -```typescript -const evtShapeOrUndefined = Evt.create(); - -evtShapeOrUndefined.$attach( - shape => !shape ? - null : - (() => { - switch (shape.type) { - case "CIRCLE": return [shape.radius] as const; - case "SQUARE": return [shape.sideLength] as const; - } - })(), - radiusOrSide => { /* ... */ } -); -``` - -Generally const assertions can help you narrow down the return type of your operator. In the following example without the const assertions `data` is inferred as being `string | number` , with the const assertions it is `"TOO LARGE" | number` - -```typescript -import { Evt } from "evt"; - -const evtN = Evt.create(); - -evtN.$attach( - n => [ n>43 ? "TOO LARGE" as const : n ], - data=> { /* ... */ } -); -``` - -#### Do write single instruction function, try to avoid explicit return. - -This is more a guideline than a requirement but you should favor `data => expression` over `data=> { ...return x; }` wherever possible for multiple reasons: - -1. It is much less likely to inadvertently produce a side effect writing a single expression function than it is writing a function with explicit returns. -2. Operators are meant to be easily readable. If you think the operator you need is too complex to be clearly expressed by a single instruction, you should consider splitting it in multiple operators and using the compose function introduced in the next section. -3. It is easier for TypeScript to infer the return type of single expression functions. - -Here is the previous example using explicit returns just to show you that the return type has to be explicitly specified, this code does not copy without it. - -```typescript -import { Evt } from "evt"; - -const evtN = Evt.create(); - -//🚨 This is NOT recomanded 🚨... -evtN.$attach( - (n): [ "TOO LARGE" | number ] => { - if( n > 43 ){ - return [ "TOO LARGE" ]; - } - return [n]; - }, - data=> { /* ... */ } -);. -``` - -## `compose(op1, op2, ..., opn)` - -$$ -op_n \circ... \circ op_2 \circ op_1 -$$ - -Operators can be composed \( aka piped \) to achieve more complex behaviour. - -Example composing type guards with fλ: - -```typescript -import { Evt, compose } from "evt"; - -const evtShape= Evt.create(); - -evtShape.$attach( - compose( - matchCircle, - ({ radius })=> [ radius ] - ), - radius => console.log(radius) -); - -//Prints nothing, Square does not matchCircle -evtShape.post({ "type": "SQUARE", "sideLength": 10 }); -//Prints "12" -evtShape.post({ "type": "CIRCLE", "radius": 12 }); -``` - -Example with [`on`](https://docs.evt.land/overview#eventemitter-comparison) \( operator used to do things à la `EventEmitter`\) - -```typescript -import { Evt, to, compose } from "evt"; - -const evt = Evt.create< - ["text", string] | - ["time", number] ->(); - -evt.$attach( - compose( - to("text"), - text => [ text.toUpperCase() ] - ) - text => console.log(text) -); - -evt.post(["text", "hi!"]); //Prints "HI!" ( uppercase ) -``` - -Example composing three fλ to count the number of different words in a sentence: - -```typescript -import { Evt, compose } from "evt"; - -const evtSentence = Evt.create(); - -evtSentence.$attach( - compose( - str=> [ str.toLowerCase().split(" ") ], - arr=> [ new Set(arr) ], - set=> [ set.size ] - ), - numberOfUniqWordInSentence => console.log(numberOfUniqWordInSentence) -); - -evtSentence.post("Hello World"); //Prints "2" -evtSentence.post("Boys will be boys"); //Prints "3", "boys" appears twice. -``` - -Using stateful fλ operators to implement `throttleTime(duration)`, an operator that let through at most one event every `duration` milliseconds. - -```typescript -import { Evt, compose } from "evt"; - -const throttleTime = (duration: number) => - compose( - [ - (data, { lastClick }) => - Date.now() - lastClick < duration ? - null : - [{ data, "lastClick": Date.now() }], - { "lastClick": 0, "data": null as any } - ], - ({ data }) => [data] - ) - ; - -const evtText = Evt.create(); - -evtText.$attach( - throttleTime(1000), //<= At most one event per second is handled. - text => console.log(text) -); - -setTimeout(()=>evtText.post("A"), 0); //Prints "A" -//Prints nothing, the previous event was handled less than 1 second ago. -setTimeout(()=>evtText.post("B"), 500); -//Prints nothing, the previous event was handled less than 1 second ago. -setTimeout(()=>evtText.post("B"), 750); -setTimeout(()=>evtText.post("C"), 1001); //Prints "C" -setTimeout(()=>evtText.post("D"), 2500); //Prints "D" -``` - -[**Run the example**](https://stackblitz.com/edit/evt-dkx3kn?embed=1&file=index.ts&hideExplorer=1) - -{% hint style="warning" %} -Unless all the operators passed as arguments are stateless the operator returned by `compose` is **not** reusable. -{% endhint %} - -```typescript -import { Evt, compose } from "evt"; - -//Never do that: -{ - -const op= compose( - [(str, acc)=>[`${acc} ${str}`], ""], - str=> [str.length] -); - -const evtText= Evt.create(); - -evtText.$attach(op, n=> console.log(n)); -evtText.$attach(op, n=> console.log(n)); - -evtText.post("Hello World"); //Prints "12 24" ❌ - -} - -console.log(""); - -//Do that instead: -{ - -const getOp= ()=> compose( - [(str, acc)=>[`${acc} ${str}`], ""], - str=> [str.length] -); - -const evtText= Evt.create(); - -evtText.$attach(getOp(), n=> console.log(n)); -evtText.$attach(getOp(), n=> console.log(n)); - -evtText.post("Hello World"); //Prints "12 12" ✅ - -} -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-gmzzzx?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -## Explicitly using the type alias - -The `Operator` type alias defines what functions qualify as a valid EVT operaor. The type can be used as a scaffolder to write fλ. - -In `Operator` , `T` design the type of the event data and `U` design the type of the data spitted out by the operator. For filters operator `U=T`. - -```typescript -import { Operator } from "evt"; - -//A function that take an EVT operator as argument. -declare function f(op: Operator): void; - -//Les's say you know you want to create an operator that take string -//and spit out number you can use the type alias as scaffolding. -const myStatelessFλOp: Operator.fλ = - str => str.startsWith("H")? null : [ str.length ]; -//The shape argument is inferred as being a string and TS control that you -//are returning a number (str.length) as you should. - -f(myStatelessFλOp); //OK, f Operator.fλ is assignable to Operator. - -//An other example creating an stateful operator -const myStatefulFλOp: Operator.fλ = - [ - (data, prev) => [prev + data.length], - 0 - ]; - -f(myStatefulFλOp); //OK, f - -//Filter and TypeGuard don't need scaffolding but they are valid Operator - -f((data: string) => data.startsWith("H")); // OK, TS infer f -f((n: number): n is 0 | 1 => n === 0 || n === 1); // OK, TS infer f -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-agatnh?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -## Generic operators built in - -{% hint style="warning" %} -Generic operators such as `bufferTime` `debounceTime`, `skip`, `take`, `switchMap`, `mergeMap` and `reduce`Will be added later on alongside creators. To implement those we need a third type of operator called `AutonomousOperators` that will ship in the next major release. -{% endhint %} - -Some generic operators are provided in `"evt/dist/lib/util/genericOperators"` such as `scan`, `throttleTime` or `to` but that's about it. - -```typescript -//Importing custom operator chunksOf that is not exported by default. -import { chuncksOf } from "evt/dist/lib/util/genericOperators"; -``` - -## Where to use operators - -Operators functions can be used with: - -* All the [`evt.attach*(...)`](https://docs.ts-evt.dev/api-doc/evt#evt-usd-attach-methods) methods. [They have to be prefixed with `$` when used with fλ](https://docs.ts-evt.dev/api/evt/evt.-usd-attach-...-methods#the-usd-prefix). -* The [`evt.waitFor(...)`](https://docs.ts-evt.dev/api-doc/evt#evt-waitfor) method -* The [`evt.pipe(...)`](https://docs.ts-evt.dev/api-doc/evt#evt-pipe) method. - diff --git a/docs/api/statefulevt.md b/docs/api/statefulevt.md deleted file mode 100644 index 4176208c..00000000 --- a/docs/api/statefulevt.md +++ /dev/null @@ -1,203 +0,0 @@ -# StatefulEvt<T> - -A `StatefulEvt` is an Evt stat keep a reference to the last value posted. - -You can think of it as way to observe when a value is changed. - -## `.state` - -Property type: `T` - -reading the property gives the last event data posted. Setting the property \(`evt.state = data`\) is equivalent of calling invoking `.post(data)`. - -```typescript -import { Evt } from "evt"; - -const evtCount = Evt.create(0); // Equivalent wit new StatefulEvt(0) - -evtCount.attach(console.log); - -console.log(evtCount.state); //Pints "state: 0" - -evtIsConnected.post(1); //Pints "1" - -console.log(evtCount.state); //Prints "1"; - -evtCount.state++; //Prints "2" - -console.log(evtCount.state); //Pints "2"; -``` - -## `.evtChange` - -Property type: `ReadonlyStatefulEvt` - -The `.evtChange` property is an `Evt` that post only when the `.state` has changed. \( or when post is made via `.postForceChange()` \) - -```typescript -import { Evt } from "evt"; - -const evtIsConnected = Evt.create(false); - -evtIsConnected.attach(console.log); - -evtIsConnected.state = false; //Prints nothing .state was already false. -evtIsConnected.state = true; //Prints "true"; -``` - -## `.evtDiff` - -Property type: `NonPostableEvt<{prevState:T; newState: T}>` - -Posted every time the Evt is posted. Used to compare the previous state with the new state. - -```typescript -import { Evt } from "evt"; - -const evtColor = Evt.create<"BLUE"|"RED"|"WHITE">("BLUE"); -evtColor.evtDiff.attach( - ({ prevState, newState})=> console.log(`${prevState}=>${newState}`) -); - -evtColor.state= "BLUE"; //Prints "BLUE=>BLUE" -evtColor.state= "WHITE"; //Prints "BLUE=>WHITE" -``` - -## `.evtChangeDiff` - -Property type: `NonPostableEvt<{prevState:T; newState: T}>` - -Same than .evtDiff but post only when .evtChang post. - -```typescript -import { Evt } from "evt"; - -const evtColor = Evt.create<"BLUE"|"RED"|"WHITE">("BLUE"); -evtColor.evtChangeDiff.attach( - ({ prevState, newState})=> console.log(`${prevState}=>${newState}`) -); - -evtColor.state= "BLUE"; //Prints nothing -evtColor.state= "WHITE"; //Prints "BLUE=>WHITE" -``` - -## `.pipe(...)` - -Same as [`evt.pipe(...)`](https://docs.evt.land/api/evt/pipe) but return a `StatefulEvt`. Be aware that the current state of the `StatefulEvt` must be matched by the operator \( if any \) when invoking `.pipe()`, elst an exception will be thrown. - -```typescript -import { Evt } from "evt"; - -type Circle = { - color: "WHITE" | "RED"; - radius: number; -}; - -const evtSelectedCircle = Evt.create({ "color": "RED", "radius": 3 }); - -const evtSelectedCricleColor = - evtSelectedCircle.pipe(circle=> [ cicle.color ]); - -evtSelectedCircleColor.attach(console.log); -``` - -## Converting an `Evt` into a `StatefulEvt` - -Use the method method .toStateful\(initialState\) of Evt. Example: - -```typescript -import { Evt } from "evt"; - - -const evtClickCount= Evt.from(document,"click") - .pipe([(...[,count])=>[count+1],0]) - .toStateful(0); - -//...user click 3 times on the page - -console.log(evtClickCount.state); //Prints "3" -``` - -## Merging multiple `StatefulEvt`s - -```typescript -import { Evt } from "evt"; - -const evtIsBlue= Evt.create(false); -const evtIsBig= Evt.create(false); - -const evtIsBigAndBlue = Evt.merge([ - evtIsBlue.evtChange, - evtIsBig.evtChange -]) - .toStateful() - .pipe(()=> [ evtIsBlue.state && evtIsBig.state ]) - ; - -console.log(evtIsBigAndBlue.state); // Prints "false" - -evtIsBlue.state= true; - -console.log(evtIsBigAndBlue.state); // Prints "false" - -evtIsBig.state= true; - -console.log(evtIsBigAndBlue.state); // Prints "true" -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-22pavm?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -## Make a `StatefulEvt` readonly - -To prevent a StatefulEvt to be posted by parts of the code that is not supposed to StatefulEvt can be exposed as `StatefulReadonlyEvt`. - -```typescript -import { StatefulEvt, StatefulReadonlyEvt } from "evt"; - -//Return an event that post every second. -function generateEvtTick(delay: number): StatefulReadonlyEvt { - - const evtTick= new StatefulEvt(0); - - setInterval(()=> evtTick.state++, delay); - - retrun evtTick; - -} - -const evtTick= generateTick(1000); - - -evtTick.state++; // TS ERROR -evtTick.post(2); // TS ERROR -``` - -## `.postFoceChange()` - -```typescript - /** - * Post and enforce that .evtChange and .evtChangeDiff - * be posted even if the state has not changed. - * - * If no argument is passed the post is performed with the current state. - * - * Returns post count - **/ - postForceChange(wData?: readonly [T]): number; -``` - -## `.toStateless([ctx])` - -Return a stateless copy of the `Evt.` - -```typescript -import { Evt } from "evt"; - -const evtText= Evt.create("foo"); - -//x is Evt -const x= evtText.toStateless(); -``` - -`evt.toStateless()` is equivalent to `Evt.prototype.pipe.call(evt)` - diff --git a/docs/overview.md b/docs/overview.md deleted file mode 100644 index a3dc9024..00000000 --- a/docs/overview.md +++ /dev/null @@ -1,193 +0,0 @@ ---- -Description: Comparison with the other library that addresses the same concern. ---- - -# Overview - -## `EventEmitter` comparison - -Let us consider this example, use of `EventEmitter`: - -```typescript -import { EventEmitter } from "events"; - -const eventEmitter = new EventEmitter(); - -eventEmitter.on("text", text => console.log(text)); -eventEmitter.once("time", time => console.log(time)); - -eventEmitter.emit("text", "hi!"); //Prints "hi!" -eventEmitter.emit("time", 123); //Prints "123" -eventEmitter.emit("time", 1234); //Prints nothing ( once ) -``` - -In EVT the recommended approach is to give every event it's `Evt` instance. Translation of the example: - -```typescript -import { Evt } from "evt"; -//Or import { Evt } from "https://evt.land/x/evt/mod.ts" on deno - -const evtText = Evt.create(); -const evtTime = Evt.create(); - -evtText.attach(text => console.log(text)); -evtTime.attachOnce(time => console.log(time)); - -evtText.post("hi!"); -evtTime.post(123); -evtTime.post(1234); -``` - -However, the traditional approach that consists of gathering all the events in a single bus is also an option. - -```typescript -import { Evt, to } from "evt"; - -const evt = Evt.create< - [ "text", string ] | - [ "time", number ] ->(); - -evt.$attach(to("text"), text => console.log(text)); -evt.$attachOnce(to("time"), time => console.log(time)); - -evt.post(["text", "hi!"]); -evt.post(["time", 123]); -evt.post(["time", 1234]); -``` - -[**Run the example**](https://stackblitz.com/edit/evt-honvv3?embed=1&file=index.ts&hideExplorer=1) - -## RxJS comparison - -### "Get started" examples. - -Here is a translations of [the examples provided as an overview](https://rxjs-dev.firebaseapp.com/guide/overview#values) on the RxJS website. - -```typescript -import { fromEvent } from "rxjs"; -import { throttleTime, map, scan } from "rxjs/operators"; - -fromEvent(document, "click") - .pipe( - throttleTime(1000), - map(event => event.clientX), // (TS: clientX does not exsist on type Event) - scan((count, clientX) => count + clientX, 0) - ) - .subscribe(count => console.log(count)) - ; - -/* ------------------------------ */ - -import { Evt, throttleTime } from "evt"; - -Evt.from(document, "click") - .pipe( - throttleTime(1000), - event => [ event.clientX ], - [(clientX, count) => [ count + clientX ], 0] - ) - .attach(count => console.log(count)) - ; -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-q772em?embed=1&file=index.ts&hideExplorer=1) - -### RxJS operators vs EVT operator - -Unlike [RxJS operators](https://rxjs-dev.firebaseapp.com/guide/operators) that return `Observable` EVT operators are function build using native language features, no by composing other pre-existing operators or instantiating any particular class. - -Consider that we have an emitter for this data type: - -```typescript -type Data = { - type: "TEXT"; - text: string; -} | { - type: "AGE"; - age: number; -}; -``` - -We want to get a `Promise` that resolves with the next text event. - -```typescript -import { Subject } from "rxjs"; -import { filter, first, map } from "rxjs/operators"; - -const subject = new Subject(); - -const prText = subject - .pipe( - filter( - (data): data is Extract => - data.type === "TEXT" - ), - first(), - map(data => data.text) - ) - .toPromise() - ; - -/* ---------------------------------------------------------------- */ - -import { Evt } from "evt"; - -const evt = new Evt(); - -const prText = evt.waitFor( - data => data.type !== "TEXT" ? - null : [data.text] -); -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-795plc?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -Let us consider another example involving state encapsulation. Here we want to accumulate all texts events until `"STOP"` - -```typescript -import { Subject } from "rxjs"; -import { map, filter, takeWhile, scan } from "rxjs/operators"; - -const subject = new Subject(); - -subject - .pipe( - filter( - (data): data is Extract => - data.type === "TEXT" - ), - map(data=> data.text), - takeWhile(text => text !== "STOP"), - scan((prev, text) => `${prev} ${text}`, "=>") - ) - .subscribe(str => console.log(str)) - ; - -/* ---------------------------------------------------------------- */ - -import { Evt } from "evt"; - -const evtData = new Evt(); - -evtData.$attach( - [ - (data, prev) => - data.type !== "TEXT" ? - null : - data.text === "STOP" ? - "DETACH" : - [`${prev} ${data.text}`] - , - "=>" - ], //<= Stateful fλ operator - str => console.log(str) -); -``` - -\*\*\*\*[**Run the example**](https://stackblitz.com/edit/evt-xuutfw?embed=1&file=index.ts&hideExplorer=1)\*\*\*\* - -## Where to start - -The API reference documentation is full of runnable examples that should get you started in no time. - diff --git a/src/lib/Ctx.ts b/lib/Ctx.ts similarity index 83% rename from src/lib/Ctx.ts rename to lib/Ctx.ts index 6a6c3208..32ac9871 100644 --- a/src/lib/Ctx.ts +++ b/lib/Ctx.ts @@ -1,19 +1,19 @@ -import { Polyfill as Set } from "minimal-polyfills/Set"; -import { Polyfill as WeakMap } from "minimal-polyfills/WeakMap"; -import { assert } from "../tools/typeSafety/assert"; -import { typeGuard } from "../tools/typeSafety/typeGuard"; -import { LazyEvt } from "./LazyEvt"; -import { importProxy } from "./importProxy"; -import { Handler } from "./types/Handler"; -import { defineAccessors } from "../tools/typeSafety/defineAccessors"; -import { overwriteReadonlyProp } from "../tools/typeSafety/overwriteReadonlyProp"; - -type EvtLike = import("./types/helper/UnpackEvt").EvtLike; -type Evt = import("./types/interfaces").Evt; -type CtxLike = import("./types/interfaces").CtxLike; -type DoneOrAborted = import("./types/interfaces/Ctx").DoneOrAborted; - -export type Ctx = import("./types/interfaces").Ctx; +import { Polyfill as Set } from "https://raw.github.com/garronej/minimal_polyfills/2.0.1/Set.ts"; +import { Polyfill as WeakMap } from "https://raw.github.com/garronej/minimal_polyfills/2.0.1/WeakMap.ts"; +import { assert } from "../tools/typeSafety/assert.ts"; +import { typeGuard } from "../tools/typeSafety/typeGuard.ts"; +import { LazyEvt } from "./LazyEvt.ts"; +import { importProxy } from "./importProxy.ts"; +import { Handler } from "./types/Handler.ts"; +import { defineAccessors } from "../tools/typeSafety/defineAccessors.ts"; +import { overwriteReadonlyProp } from "../tools/typeSafety/overwriteReadonlyProp.ts"; + +type EvtLike = import("./types/helper/UnpackEvt.ts").EvtLike; +type Evt = import("./types/interfaces/index.ts").Evt; +type CtxLike = import("./types/interfaces/index.ts").CtxLike; +type DoneOrAborted = import("./types/interfaces/Ctx.ts").DoneOrAborted; + +export type Ctx = import("./types/interfaces/index.ts").Ctx; class CtxImpl implements Ctx{ diff --git a/src/lib/Evt.asNonPostable.ts b/lib/Evt.asNonPostable.ts similarity index 75% rename from src/lib/Evt.asNonPostable.ts rename to lib/Evt.asNonPostable.ts index 0fdba8cd..5972cebb 100644 --- a/src/lib/Evt.asNonPostable.ts +++ b/lib/Evt.asNonPostable.ts @@ -1,6 +1,6 @@ -import { ToNonPostableEvt } from "./types/helper/ToNonPostableEvt"; -type EvtLike= import("./types/helper/UnpackEvt").EvtLike; +import { ToNonPostableEvt } from "./types/helper/ToNonPostableEvt.ts"; +type EvtLike= import("./types/helper/UnpackEvt.ts").EvtLike; /** https://docs.evt.land/api/evt/asnonpostable */ export function asNonPostable>(evt: E): ToNonPostableEvt{ diff --git a/src/lib/Evt.asPostable.ts b/lib/Evt.asPostable.ts similarity index 63% rename from src/lib/Evt.asPostable.ts rename to lib/Evt.asPostable.ts index c696a8f7..948fff25 100644 --- a/src/lib/Evt.asPostable.ts +++ b/lib/Evt.asPostable.ts @@ -1,6 +1,6 @@ -import { ToPostableEvt } from "./types/helper/ToPostableEvt"; -type EvtLike= import("./types/helper/UnpackEvt").EvtLike; +import { ToPostableEvt } from "./types/helper/ToPostableEvt.ts"; +type EvtLike= import("./types/helper/UnpackEvt.ts").EvtLike; /** * https://docs.evt.land/api/evt/aspostable diff --git a/src/lib/Evt.create.ts b/lib/Evt.create.ts similarity index 70% rename from src/lib/Evt.create.ts rename to lib/Evt.create.ts index cff07706..34ff7133 100644 --- a/src/lib/Evt.create.ts +++ b/lib/Evt.create.ts @@ -1,9 +1,9 @@ -import { importProxy } from "./importProxy"; +import { importProxy } from "./importProxy.ts"; -type Evt = import("./types/interfaces").Evt; -type VoidEvt= import("./types/interfaces").VoidEvt; -type StatefulEvt = import("./types/interfaces").StatefulEvt; +type Evt = import("./types/interfaces/index.ts").Evt; +type VoidEvt= import("./types/interfaces/index.ts").VoidEvt; +type StatefulEvt = import("./types/interfaces/index.ts").StatefulEvt; /** * https://docs.evt.land/api/evt/create diff --git a/src/lib/Evt.factorize.ts b/lib/Evt.factorize.ts similarity index 63% rename from src/lib/Evt.factorize.ts rename to lib/Evt.factorize.ts index 21c2093b..d797b67c 100644 --- a/src/lib/Evt.factorize.ts +++ b/lib/Evt.factorize.ts @@ -1,7 +1,7 @@ -import { FactorizeEvt } from "./types/helper/FactorizeEvt"; +import { FactorizeEvt } from "./types/helper/FactorizeEvt.ts"; -type EvtLike = import("./types/helper/UnpackEvt").EvtLike; +type EvtLike = import("./types/helper/UnpackEvt.ts").EvtLike; /** https://docs.evt.land/api/evt/factorize */ export function factorize>( @@ -11,7 +11,7 @@ export function factorize>( } /* -import { Evt } from "./Evt"; +import { Evt } from "./Evt.ts"; const x: Evt = loosenType(new Evt()); x; const y: Evt = loosenType(new Evt()); y; */ \ No newline at end of file diff --git a/src/lib/Evt.from.ts b/lib/Evt.from.ts similarity index 91% rename from src/lib/Evt.from.ts rename to lib/Evt.from.ts index 21a7e1bb..52a0b2f4 100644 --- a/src/lib/Evt.from.ts +++ b/lib/Evt.from.ts @@ -1,15 +1,15 @@ -import { id } from "../tools/typeSafety/id"; -import { assert } from "../tools/typeSafety/assert"; -import { typeGuard } from "../tools/typeSafety/typeGuard"; -import { EventTargetLike } from "./types/EventTargetLike"; -import { mergeImpl } from "./Evt.merge"; -import { importProxy } from "./importProxy"; -import * as dom from "./types/lib.dom"; -type Evt= import("./types/interfaces/Evt").Evt; -type EvtLike = import("./types/helper/UnpackEvt").EvtLike; +import { id } from "../tools/typeSafety/id.ts"; +import { assert } from "../tools/typeSafety/assert.ts"; +import { typeGuard } from "../tools/typeSafety/typeGuard.ts"; +import { EventTargetLike } from "./types/EventTargetLike.ts"; +import { mergeImpl } from "./Evt.merge.ts"; +import { importProxy } from "./importProxy.ts"; +import * as dom from "./types/lib.dom.ts"; +type Evt= import("./types/interfaces/Evt.ts").Evt; +type EvtLike = import("./types/helper/UnpackEvt.ts").EvtLike; type OneOrMany = T | ArrayLike; -type CtxLike = import("./types/interfaces").CtxLike & { +type CtxLike = import("./types/interfaces/index.ts").CtxLike & { evtDoneOrAborted: EvtLike & { postCount: number; attachOnce(callback: ()=> void): void; }; }; diff --git a/src/lib/Evt.getCtx.ts b/lib/Evt.getCtx.ts similarity index 74% rename from src/lib/Evt.getCtx.ts rename to lib/Evt.getCtx.ts index c84ff310..b48d3901 100644 --- a/src/lib/Evt.getCtx.ts +++ b/lib/Evt.getCtx.ts @@ -1,6 +1,6 @@ -import { Polyfill as WeakMap } from "minimal-polyfills/WeakMap"; -import { importProxy } from "./importProxy"; -type VoidCtx = import("./types/interfaces").VoidCtx; +import { Polyfill as WeakMap } from "https://raw.github.com/garronej/minimal_polyfills/2.0.1/WeakMap.ts"; +import { importProxy } from "./importProxy.ts"; +type VoidCtx = import("./types/interfaces/index.ts").VoidCtx; /** * https://docs.evt.land/api/evt/getctx diff --git a/src/lib/Evt.loosenType.ts b/lib/Evt.loosenType.ts similarity index 63% rename from src/lib/Evt.loosenType.ts rename to lib/Evt.loosenType.ts index 4cd04356..3f83c6d9 100644 --- a/src/lib/Evt.loosenType.ts +++ b/lib/Evt.loosenType.ts @@ -1,7 +1,7 @@ -import { SwapEvtType } from "./types/helper/SwapEvtType"; -import { UnpackEvt } from "./types/helper/UnpackEvt"; +import { SwapEvtType } from "./types/helper/SwapEvtType.ts"; +import { UnpackEvt } from "./types/helper/UnpackEvt.ts"; -type EvtLike = import("./types/helper/UnpackEvt").EvtLike; +type EvtLike = import("./types/helper/UnpackEvt.ts").EvtLike; /** * https://docs.evt.land/api/evt/loosenType @@ -14,7 +14,7 @@ export function loosenType, SupersetOfT>( } /* -import { Evt } from "./Evt"; +import { Evt } from "./Evt.ts"; const x: Evt = loosenType(new Evt()); x; const y: Evt = loosenType(new Evt()); y; */ diff --git a/src/lib/Evt.merge.ts b/lib/Evt.merge.ts similarity index 79% rename from src/lib/Evt.merge.ts rename to lib/Evt.merge.ts index cad5f7f0..df85ea78 100644 --- a/src/lib/Evt.merge.ts +++ b/lib/Evt.merge.ts @@ -1,10 +1,10 @@ -import { UnpackEvt } from "./types/helper/UnpackEvt"; -import { importProxy } from "./importProxy"; +import { UnpackEvt } from "./types/helper/UnpackEvt.ts"; +import { importProxy } from "./importProxy.ts"; -type Evt= import("./types/interfaces").Evt; -type CtxLike = import("./types/interfaces").CtxLike; +type Evt= import("./types/interfaces/index.ts").Evt; +type CtxLike = import("./types/interfaces/index.ts").CtxLike; -type EvtLike = import("./types/helper/UnpackEvt").EvtLike & { +type EvtLike = import("./types/helper/UnpackEvt.ts").EvtLike & { attach(ctx: CtxLike, callback: (data: T)=> void): void; attach(callback: (data: T)=> void): void; }; diff --git a/src/lib/Evt.newCtx.ts b/lib/Evt.newCtx.ts similarity index 57% rename from src/lib/Evt.newCtx.ts rename to lib/Evt.newCtx.ts index a77a4b9c..6ef93054 100644 --- a/src/lib/Evt.newCtx.ts +++ b/lib/Evt.newCtx.ts @@ -1,7 +1,7 @@ -import { importProxy } from "./importProxy"; +import { importProxy } from "./importProxy.ts"; -type Ctx = import("./Ctx").Ctx; -type VoidCtx = import("./types/interfaces").VoidCtx; +type Ctx = import("./Ctx.ts").Ctx; +type VoidCtx = import("./types/interfaces/index.ts").VoidCtx; /** * https://docs.evt.land/api/evt/newctx diff --git a/src/lib/Evt.parsePropsFromArgs.ts b/lib/Evt.parsePropsFromArgs.ts similarity index 95% rename from src/lib/Evt.parsePropsFromArgs.ts rename to lib/Evt.parsePropsFromArgs.ts index e37b3cd2..241276f5 100644 --- a/src/lib/Evt.parsePropsFromArgs.ts +++ b/lib/Evt.parsePropsFromArgs.ts @@ -1,10 +1,10 @@ -import { Handler } from "./types/Handler" -import { Operator } from "./types/Operator" -import { id } from "../tools/typeSafety/id"; -import { compose } from "./util/compose"; -import { typeGuard } from "../tools/typeSafety/typeGuard" -type CtxLike = import("./types/interfaces").CtxLike; +import { Handler } from "./types/Handler.ts" +import { Operator } from "./types/Operator.ts" +import { id } from "../tools/typeSafety/id.ts"; +import { compose } from "./util/compose.ts"; +import { typeGuard } from "../tools/typeSafety/typeGuard.ts" +type CtxLike = import("./types/interfaces/index.ts").CtxLike; export function matchAll() { return true; } diff --git a/src/lib/Evt.ts b/lib/Evt.ts similarity index 93% rename from src/lib/Evt.ts rename to lib/Evt.ts index d7490360..38c9cc0f 100644 --- a/src/lib/Evt.ts +++ b/lib/Evt.ts @@ -1,33 +1,33 @@ -import "minimal-polyfills/Array.prototype.find"; -import { importProxy } from "./importProxy"; -import { create } from "./Evt.create"; -import { getCtxFactory } from "./Evt.getCtx"; -import { factorize } from "./Evt.factorize"; -import { merge } from "./Evt.merge"; -import { from } from "./Evt.from"; -import { useEffect } from "./Evt.useEffect"; -import { asPostable } from "./Evt.asPostable"; -import { asNonPostable } from "./Evt.asNonPostable"; -import { parsePropsFromArgs, matchAll } from "./Evt.parsePropsFromArgs"; -import { newCtx } from "./Evt.newCtx"; -import { LazyEvt } from "./LazyEvt"; -import { defineAccessors } from "../tools/typeSafety/defineAccessors"; -import { invokeOperator } from "./util/invokeOperator"; -import { Polyfill as Map, LightMap } from "minimal-polyfills/Map"; -import { Polyfill as WeakMap } from "minimal-polyfills/WeakMap"; -import * as runExclusive from "run-exclusive"; -import { EvtError } from "./types/EvtError"; -import { overwriteReadonlyProp } from "../tools/typeSafety/overwriteReadonlyProp"; -import { typeGuard } from "../tools/typeSafety/typeGuard"; -import { encapsulateOpState } from "./util/encapsulateOpState"; -import { Deferred } from "../tools/Deferred"; -import { loosenType } from "./Evt.loosenType"; -import { CtxLike } from "./types/interfaces/CtxLike"; - -import { Handler } from "./types/Handler"; -import { Operator } from "./types/Operator"; -type NonPostableEvt = import("./types/interfaces").NonPostableEvt; -type StatefulEvt = import("./types/interfaces").StatefulEvt; +import "https://raw.github.com/garronej/minimal_polyfills/2.0.1/Array.prototype.find.ts"; +import { importProxy } from "./importProxy.ts"; +import { create } from "./Evt.create.ts"; +import { getCtxFactory } from "./Evt.getCtx.ts"; +import { factorize } from "./Evt.factorize.ts"; +import { merge } from "./Evt.merge.ts"; +import { from } from "./Evt.from.ts"; +import { useEffect } from "./Evt.useEffect.ts"; +import { asPostable } from "./Evt.asPostable.ts"; +import { asNonPostable } from "./Evt.asNonPostable.ts"; +import { parsePropsFromArgs, matchAll } from "./Evt.parsePropsFromArgs.ts"; +import { newCtx } from "./Evt.newCtx.ts"; +import { LazyEvt } from "./LazyEvt.ts"; +import { defineAccessors } from "../tools/typeSafety/defineAccessors.ts"; +import { invokeOperator } from "./util/invokeOperator.ts"; +import { Polyfill as Map, LightMap } from "https://raw.github.com/garronej/minimal_polyfills/2.0.1/Map.ts"; +import { Polyfill as WeakMap } from "https://raw.github.com/garronej/minimal_polyfills/2.0.1/WeakMap.ts"; +import * as runExclusive from "https://raw.github.com/garronej/run_exclusive/2.1.18/mod.ts"; +import { EvtError } from "./types/EvtError.ts"; +import { overwriteReadonlyProp } from "../tools/typeSafety/overwriteReadonlyProp.ts"; +import { typeGuard } from "../tools/typeSafety/typeGuard.ts"; +import { encapsulateOpState } from "./util/encapsulateOpState.ts"; +import { Deferred } from "../tools/Deferred.ts"; +import { loosenType } from "./Evt.loosenType.ts"; +import { CtxLike } from "./types/interfaces/CtxLike.ts"; + +import { Handler } from "./types/Handler.ts"; +import { Operator } from "./types/Operator.ts"; +type NonPostableEvt = import("./types/interfaces/index.ts").NonPostableEvt; +type StatefulEvt = import("./types/interfaces/index.ts").StatefulEvt; //NOTE: Deno can't use NodeJS type def ( obviously ) type Timer= { _timerBrand: any; }; @@ -35,7 +35,7 @@ const safeSetTimeout = (callback: () => void, ms: number): Timer => setTimeout(c const safeClearTimeout = (timer: Timer): void => clearTimeout(timer as any); /** https://docs.evt.land/api/evt */ -export type Evt = import("./types/interfaces").Evt; +export type Evt = import("./types/interfaces/index.ts").Evt; class EvtImpl implements Evt { diff --git a/src/lib/Evt.useEffect.ts b/lib/Evt.useEffect.ts similarity index 100% rename from src/lib/Evt.useEffect.ts rename to lib/Evt.useEffect.ts diff --git a/src/lib/LazyEvt.ts b/lib/LazyEvt.ts similarity index 86% rename from src/lib/LazyEvt.ts rename to lib/LazyEvt.ts index ad49b666..62877746 100644 --- a/src/lib/LazyEvt.ts +++ b/lib/LazyEvt.ts @@ -1,7 +1,7 @@ -import { overwriteReadonlyProp } from "../tools/typeSafety/overwriteReadonlyProp"; -import { importProxy } from "./importProxy"; -type Evt = import("./types/interfaces").Evt; -import { defineAccessors } from "../tools/typeSafety/defineAccessors"; +import { overwriteReadonlyProp } from "../tools/typeSafety/overwriteReadonlyProp.ts"; +import { importProxy } from "./importProxy.ts"; +type Evt = import("./types/interfaces/index.ts").Evt; +import { defineAccessors } from "../tools/typeSafety/defineAccessors.ts"; export class LazyEvt { diff --git a/src/lib/LazyStatefulEvt.ts b/lib/LazyStatefulEvt.ts similarity index 88% rename from src/lib/LazyStatefulEvt.ts rename to lib/LazyStatefulEvt.ts index ac10f867..1874290b 100644 --- a/src/lib/LazyStatefulEvt.ts +++ b/lib/LazyStatefulEvt.ts @@ -1,7 +1,7 @@ -import { overwriteReadonlyProp } from "../tools/typeSafety/overwriteReadonlyProp"; -import { importProxy } from "./importProxy"; -type StatefulEvt = import("./types/interfaces").StatefulEvt; -import { defineAccessors } from "../tools/typeSafety/defineAccessors"; +import { overwriteReadonlyProp } from "../tools/typeSafety/overwriteReadonlyProp.ts"; +import { importProxy } from "./importProxy.ts"; +type StatefulEvt = import("./types/interfaces/index.ts").StatefulEvt; +import { defineAccessors } from "../tools/typeSafety/defineAccessors.ts"; export class LazyStatefulEvt { diff --git a/src/lib/StatefulEvt.ts b/lib/StatefulEvt.ts similarity index 81% rename from src/lib/StatefulEvt.ts rename to lib/StatefulEvt.ts index 730345d1..7f559e0d 100644 --- a/src/lib/StatefulEvt.ts +++ b/lib/StatefulEvt.ts @@ -1,19 +1,19 @@ -import "minimal-polyfills/Object.is"; -import { defineAccessors } from "../tools/typeSafety/defineAccessors"; -import { LazyEvt } from "./LazyEvt"; -import { LazyStatefulEvt } from "./LazyStatefulEvt"; -import { importProxy } from "./importProxy"; -import { invokeOperator } from "./util/invokeOperator"; -import { Operator } from "./types/Operator"; -import { parsePropsFromArgs } from "./Evt.parsePropsFromArgs"; -import { CtxLike } from "./types/interfaces/CtxLike"; -type Diff = import("./types/interfaces").Diff; -type NonPostableEvt = import("./types/interfaces").NonPostableEvt; -type StatefulReadonlyEvt= import("./types/interfaces").StatefulReadonlyEvt; -import { Evt } from "./Evt"; +import "https://raw.github.com/garronej/minimal_polyfills/2.0.1/Object.is.ts"; +import { defineAccessors } from "../tools/typeSafety/defineAccessors.ts"; +import { LazyEvt } from "./LazyEvt.ts"; +import { LazyStatefulEvt } from "./LazyStatefulEvt.ts"; +import { importProxy } from "./importProxy.ts"; +import { invokeOperator } from "./util/invokeOperator.ts"; +import { Operator } from "./types/Operator.ts"; +import { parsePropsFromArgs } from "./Evt.parsePropsFromArgs.ts"; +import { CtxLike } from "./types/interfaces/CtxLike.ts"; +type Diff = import("./types/interfaces/index.ts").Diff; +type NonPostableEvt = import("./types/interfaces/index.ts").NonPostableEvt; +type StatefulReadonlyEvt= import("./types/interfaces/index.ts").StatefulReadonlyEvt; +import { Evt } from "./Evt.ts"; /** https://docs.evt.land/api/statefulevt */ -export type StatefulEvt = import("./types/interfaces").StatefulEvt; +export type StatefulEvt = import("./types/interfaces/index.ts").StatefulEvt; class StatefulEvtImpl extends Evt implements StatefulEvt { diff --git a/lib/importProxy.ts b/lib/importProxy.ts new file mode 100644 index 00000000..f412bc0d --- /dev/null +++ b/lib/importProxy.ts @@ -0,0 +1,11 @@ + + +/** Manually handling circular import so React Native does not gives warning. */ +export const importProxy: { + Ctx: typeof import("./Ctx.ts").Ctx; + Evt: typeof import("./Evt.ts").Evt; + StatefulEvt: typeof import("./StatefulEvt.ts").StatefulEvt; +} = {} as any; + + + diff --git a/lib/index.ts b/lib/index.ts new file mode 100644 index 00000000..105b8e33 --- /dev/null +++ b/lib/index.ts @@ -0,0 +1,9 @@ + +export * from "./types/index.ts"; +export * from "./util/index.ts"; + +export { Ctx } from "./Ctx.ts"; +export { Evt } from "./Evt.ts"; +export { StatefulEvt } from "./StatefulEvt.ts"; + +export { matchVoid } from "../tools/typeSafety/matchVoid.ts"; diff --git a/src/lib/types/EventTargetLike.ts b/lib/types/EventTargetLike.ts similarity index 98% rename from src/lib/types/EventTargetLike.ts rename to lib/types/EventTargetLike.ts index d940ea2d..351e1961 100644 --- a/src/lib/types/EventTargetLike.ts +++ b/lib/types/EventTargetLike.ts @@ -1,5 +1,5 @@ -import { typeGuard } from "../../tools/typeSafety"; +import { typeGuard } from "../../tools/typeSafety/index.ts"; export type EventTargetLike = EventTargetLike.HasEventTargetAddRemove | diff --git a/src/lib/types/EvtError.ts b/lib/types/EvtError.ts similarity index 100% rename from src/lib/types/EvtError.ts rename to lib/types/EvtError.ts diff --git a/src/lib/types/Handler.ts b/lib/types/Handler.ts similarity index 89% rename from src/lib/types/Handler.ts rename to lib/types/Handler.ts index 33a62156..37147ebd 100644 --- a/src/lib/types/Handler.ts +++ b/lib/types/Handler.ts @@ -1,6 +1,6 @@ -import { Operator } from "./Operator"; -type EvtLike= import("../types/helper/UnpackEvt").EvtLike; -type CtxLike = import("../types/interfaces").CtxLike; +import { Operator } from "./Operator.ts"; +type EvtLike= import("../types/helper/UnpackEvt.ts").EvtLike; +type CtxLike = import("../types/interfaces/index.ts").CtxLike; /** https://docs.evt.land/api/handler */ export type Handler | undefined = CtxLike | undefined> = diff --git a/src/lib/types/Operator.ts b/lib/types/Operator.ts similarity index 96% rename from src/lib/types/Operator.ts rename to lib/types/Operator.ts index 7f5a0f8e..80160849 100644 --- a/src/lib/types/Operator.ts +++ b/lib/types/Operator.ts @@ -1,6 +1,6 @@ -import { typeGuard } from "../../tools/typeSafety"; -type CtxLike = import("./interfaces").CtxLike; -type VoidCtxLike = import("./interfaces").VoidCtxLike; +import { typeGuard } from "../../tools/typeSafety/index.ts"; +type CtxLike = import("./interfaces/index.ts").CtxLike; +type VoidCtxLike = import("./interfaces/index.ts").VoidCtxLike; /** https://docs.evt.land/api/operator */ diff --git a/src/lib/types/helper/FactorizeEvt.ts b/lib/types/helper/FactorizeEvt.ts similarity index 53% rename from src/lib/types/helper/FactorizeEvt.ts rename to lib/types/helper/FactorizeEvt.ts index 6b0d9611..7e128213 100644 --- a/src/lib/types/helper/FactorizeEvt.ts +++ b/lib/types/helper/FactorizeEvt.ts @@ -1,7 +1,7 @@ -import { SwapEvtType } from "./SwapEvtType"; -import { UnpackEvt } from "./UnpackEvt"; -type EvtLike= import("./UnpackEvt").EvtLike; +import { SwapEvtType } from "./SwapEvtType.ts"; +import { UnpackEvt } from "./UnpackEvt.ts"; +type EvtLike= import("./UnpackEvt.ts").EvtLike; /** https://docs.evt.land/api/helpertypes#swapevttype-less-than-e-t-greater-than */ export type FactorizeEvt> = SwapEvtType>; diff --git a/src/lib/types/helper/SwapEvtType.ts b/lib/types/helper/SwapEvtType.ts similarity index 53% rename from src/lib/types/helper/SwapEvtType.ts rename to lib/types/helper/SwapEvtType.ts index b9212a6f..2459c948 100644 --- a/src/lib/types/helper/SwapEvtType.ts +++ b/lib/types/helper/SwapEvtType.ts @@ -1,9 +1,9 @@ -type StatefulEvt = import("../interfaces").StatefulEvt; -type StatefulReadonlyEvt = import("../interfaces").StatefulReadonlyEvt; -type Evt = import("../interfaces").Evt; -type NonPostableEvt = import("../interfaces").NonPostableEvt; -type EvtLike = import("./UnpackEvt").EvtLike; -type VoidEvt = import("../interfaces").VoidEvt; +type StatefulEvt = import("../interfaces/index.ts").StatefulEvt; +type StatefulReadonlyEvt = import("../interfaces/index.ts").StatefulReadonlyEvt; +type Evt = import("../interfaces/index.ts").Evt; +type NonPostableEvt = import("../interfaces/index.ts").NonPostableEvt; +type EvtLike = import("./UnpackEvt.ts").EvtLike; +type VoidEvt = import("../interfaces/index.ts").VoidEvt; type UseVoidEvt = E extends Evt ? VoidEvt : E; diff --git a/src/lib/types/helper/ToNonPostableEvt.ts b/lib/types/helper/ToNonPostableEvt.ts similarity index 73% rename from src/lib/types/helper/ToNonPostableEvt.ts rename to lib/types/helper/ToNonPostableEvt.ts index 2b2c0436..0304a42e 100644 --- a/src/lib/types/helper/ToNonPostableEvt.ts +++ b/lib/types/helper/ToNonPostableEvt.ts @@ -1,8 +1,8 @@ -type EvtLike = import("./UnpackEvt").EvtLike; -type StatefulPostable = import("../interfaces").StatefulPostable; -type NonPostableEvt = import("../interfaces").NonPostableEvt; -type StatefulReadonlyEvt = import("../interfaces").StatefulReadonlyEvt; +type EvtLike = import("./UnpackEvt.ts").EvtLike; +type StatefulPostable = import("../interfaces/index.ts").StatefulPostable; +type NonPostableEvt = import("../interfaces/index.ts").NonPostableEvt; +type StatefulReadonlyEvt = import("../interfaces/index.ts").StatefulReadonlyEvt; //NOTE: Omit only introduced in 3.5 /** diff --git a/src/lib/types/helper/ToPostableEvt.ts b/lib/types/helper/ToPostableEvt.ts similarity index 57% rename from src/lib/types/helper/ToPostableEvt.ts rename to lib/types/helper/ToPostableEvt.ts index 596d07e5..d1e76660 100644 --- a/src/lib/types/helper/ToPostableEvt.ts +++ b/lib/types/helper/ToPostableEvt.ts @@ -1,11 +1,11 @@ -type EvtLike = import("./UnpackEvt").EvtLike; -type StatefulPostable = import("../interfaces").StatefulPostable; -type Postable = import("../interfaces").Postable; -type NonPostableEvt = import("../interfaces").NonPostableEvt; -type StatefulReadonlyEvt = import("../interfaces").StatefulReadonlyEvt; -type StatefulEvt = import("../interfaces").StatefulEvt; -type Evt = import("../interfaces").Evt; -type VoidEvt = import("../interfaces").VoidEvt; +type EvtLike = import("./UnpackEvt.ts").EvtLike; +type StatefulPostable = import("../interfaces/index.ts").StatefulPostable; +type Postable = import("../interfaces/index.ts").Postable; +type NonPostableEvt = import("../interfaces/index.ts").NonPostableEvt; +type StatefulReadonlyEvt = import("../interfaces/index.ts").StatefulReadonlyEvt; +type StatefulEvt = import("../interfaces/index.ts").StatefulEvt; +type Evt = import("../interfaces/index.ts").Evt; +type VoidEvt = import("../interfaces/index.ts").VoidEvt; type UseVoidEvt = E extends Evt ? VoidEvt : E; diff --git a/src/lib/types/helper/UnpackCtx.ts b/lib/types/helper/UnpackCtx.ts similarity index 100% rename from src/lib/types/helper/UnpackCtx.ts rename to lib/types/helper/UnpackCtx.ts diff --git a/src/lib/types/helper/UnpackEvt.ts b/lib/types/helper/UnpackEvt.ts similarity index 100% rename from src/lib/types/helper/UnpackEvt.ts rename to lib/types/helper/UnpackEvt.ts diff --git a/lib/types/helper/index.ts b/lib/types/helper/index.ts new file mode 100644 index 00000000..b690b7ee --- /dev/null +++ b/lib/types/helper/index.ts @@ -0,0 +1,6 @@ +export { FactorizeEvt } from "./FactorizeEvt.ts"; +export { SwapEvtType } from "./SwapEvtType.ts"; +export { ToPostableEvt } from "./ToPostableEvt.ts"; +export { ToNonPostableEvt } from "./ToNonPostableEvt.ts"; +export { UnpackCtx } from "./UnpackCtx.ts"; +export { UnpackEvt, EvtLike } from "./UnpackEvt.ts"; \ No newline at end of file diff --git a/lib/types/index.ts b/lib/types/index.ts new file mode 100644 index 00000000..6c55822e --- /dev/null +++ b/lib/types/index.ts @@ -0,0 +1,7 @@ +export * from "./helper/index.ts"; +export * from "./interfaces/index.ts"; +export { EventTargetLike } from "./EventTargetLike.ts"; +export { EvtError } from "./EvtError.ts"; +export { Handler } from "./Handler.ts"; +import * as dom from "./lib.dom.ts"; export { dom }; +export { Operator } from "./Operator.ts"; diff --git a/src/lib/types/interfaces/Ctx.ts b/lib/types/interfaces/Ctx.ts similarity index 93% rename from src/lib/types/interfaces/Ctx.ts rename to lib/types/interfaces/Ctx.ts index aede4899..242682ba 100644 --- a/src/lib/types/interfaces/Ctx.ts +++ b/lib/types/interfaces/Ctx.ts @@ -1,9 +1,9 @@ -import { Handler } from "../Handler"; +import { Handler } from "../Handler.ts"; -type EvtLike = import("../helper/UnpackEvt").EvtLike; -type Evt = import("./Evt").Evt; -type CtxLike = import("./CtxLike").CtxLike; +type EvtLike = import("../helper/UnpackEvt.ts").EvtLike; +type Evt = import("./Evt.ts").Evt; +type CtxLike = import("./CtxLike.ts").CtxLike; export type DoneOrAborted = DoneOrAborted.Done | DoneOrAborted.Aborted; diff --git a/src/lib/types/interfaces/CtxLike.ts b/lib/types/interfaces/CtxLike.ts similarity index 83% rename from src/lib/types/interfaces/CtxLike.ts rename to lib/types/interfaces/CtxLike.ts index ed79d94c..73d7a968 100644 --- a/src/lib/types/interfaces/CtxLike.ts +++ b/lib/types/interfaces/CtxLike.ts @@ -1,7 +1,7 @@ -import { Handler } from "../Handler"; -import { typeGuard } from "../../../tools/typeSafety/typeGuard"; -type EvtLike = import("../helper/UnpackEvt").EvtLike; +import { Handler } from "../Handler.ts"; +import { typeGuard } from "../../../tools/typeSafety/typeGuard.ts"; +type EvtLike = import("../helper/UnpackEvt.ts").EvtLike; /** * Minimal interface that an object must implement to be a valid context argument diff --git a/lib/types/interfaces/Evt.ts b/lib/types/interfaces/Evt.ts new file mode 100644 index 00000000..a6ce8b8e --- /dev/null +++ b/lib/types/interfaces/Evt.ts @@ -0,0 +1,5 @@ + +type Postable = import("./Postable.ts").Postable; +type NonPostableEvt = import("./NonPostableEvt.ts").NonPostableEvt; + +export interface Evt extends Postable, NonPostableEvt { } \ No newline at end of file diff --git a/src/lib/types/interfaces/NonPostableEvt.ts b/lib/types/interfaces/NonPostableEvt.ts similarity index 99% rename from src/lib/types/interfaces/NonPostableEvt.ts rename to lib/types/interfaces/NonPostableEvt.ts index db6f6226..a39316f3 100644 --- a/src/lib/types/interfaces/NonPostableEvt.ts +++ b/lib/types/interfaces/NonPostableEvt.ts @@ -1,9 +1,9 @@ -import { Handler } from "../Handler"; -import { Operator } from "../Operator"; +import { Handler } from "../Handler.ts"; +import { Operator } from "../Operator.ts"; -type StatefulEvt = import("./StatefulEvt").StatefulEvt; -type CtxLike = import("./CtxLike").CtxLike; -type Evt = import("./Evt").Evt; +type StatefulEvt = import("./StatefulEvt.ts").StatefulEvt; +type CtxLike = import("./CtxLike.ts").CtxLike; +type Evt = import("./Evt.ts").Evt; export interface NonPostableEvt { diff --git a/src/lib/types/interfaces/Postable.ts b/lib/types/interfaces/Postable.ts similarity index 100% rename from src/lib/types/interfaces/Postable.ts rename to lib/types/interfaces/Postable.ts diff --git a/lib/types/interfaces/StatefulEvt.ts b/lib/types/interfaces/StatefulEvt.ts new file mode 100644 index 00000000..b080e6ad --- /dev/null +++ b/lib/types/interfaces/StatefulEvt.ts @@ -0,0 +1,10 @@ + +type StatefulReadonlyEvt = import("./StatefulReadonlyEvt.ts").StatefulReadonlyEvt; +type StatefulPostable = import("./StatefulPostable.ts").StatefulPostable; + +export interface StatefulEvt extends StatefulReadonlyEvt, StatefulPostable { + + /** https://docs.evt.land/api/statefulevt#state */ + state: T; + +}; diff --git a/src/lib/types/interfaces/StatefulPostable.ts b/lib/types/interfaces/StatefulPostable.ts similarity index 78% rename from src/lib/types/interfaces/StatefulPostable.ts rename to lib/types/interfaces/StatefulPostable.ts index 4283dce1..6cc87f7c 100644 --- a/src/lib/types/interfaces/StatefulPostable.ts +++ b/lib/types/interfaces/StatefulPostable.ts @@ -1,5 +1,5 @@ -type Postable= import("./Postable").Postable; +type Postable= import("./Postable.ts").Postable; export interface StatefulPostable extends Postable { diff --git a/src/lib/types/interfaces/StatefulReadonlyEvt.ts b/lib/types/interfaces/StatefulReadonlyEvt.ts similarity index 94% rename from src/lib/types/interfaces/StatefulReadonlyEvt.ts rename to lib/types/interfaces/StatefulReadonlyEvt.ts index c3cd7794..07d39457 100644 --- a/src/lib/types/interfaces/StatefulReadonlyEvt.ts +++ b/lib/types/interfaces/StatefulReadonlyEvt.ts @@ -1,10 +1,10 @@ -import { Operator } from "../Operator"; +import { Operator } from "../Operator.ts"; -type NonPostableEvt = import("./NonPostableEvt").NonPostableEvt; -type CtxLike = import("./CtxLike").CtxLike; -type StatefulEvt = import("./StatefulEvt").StatefulEvt; -type Evt = import("./Evt").Evt; +type NonPostableEvt = import("./NonPostableEvt.ts").NonPostableEvt; +type CtxLike = import("./CtxLike.ts").CtxLike; +type StatefulEvt = import("./StatefulEvt.ts").StatefulEvt; +type Evt = import("./Evt.ts").Evt; export type StateDiff = { prevState: T, newState: T }; diff --git a/src/lib/types/interfaces/VoidCtx.ts b/lib/types/interfaces/VoidCtx.ts similarity index 72% rename from src/lib/types/interfaces/VoidCtx.ts rename to lib/types/interfaces/VoidCtx.ts index b129722c..f77c0847 100644 --- a/src/lib/types/interfaces/VoidCtx.ts +++ b/lib/types/interfaces/VoidCtx.ts @@ -1,7 +1,7 @@ -import { Handler } from "../Handler"; +import { Handler } from "../Handler.ts"; -type Ctx = import("./Ctx").Ctx; +type Ctx = import("./Ctx.ts").Ctx; /** * https://docs.evt.land/api/evt/ctx diff --git a/src/lib/types/interfaces/VoidEvt.ts b/lib/types/interfaces/VoidEvt.ts similarity index 89% rename from src/lib/types/interfaces/VoidEvt.ts rename to lib/types/interfaces/VoidEvt.ts index ca8aba53..e65583fd 100644 --- a/src/lib/types/interfaces/VoidEvt.ts +++ b/lib/types/interfaces/VoidEvt.ts @@ -1,5 +1,5 @@ -type Evt = import("./Evt").Evt; +type Evt = import("./Evt.ts").Evt; /** * https://docs.evt.land/api/evt/create#why-voidevt-and-not-evt-less-than-void-greater-than diff --git a/lib/types/interfaces/index.ts b/lib/types/interfaces/index.ts new file mode 100644 index 00000000..ed4c431e --- /dev/null +++ b/lib/types/interfaces/index.ts @@ -0,0 +1,10 @@ +export { Ctx, DoneOrAborted } from "./Ctx.ts"; +export { CtxLike, VoidCtxLike } from "./CtxLike.ts"; +export { Evt } from "./Evt.ts"; +export { NonPostableEvt } from "./NonPostableEvt.ts"; +export { Postable } from "./Postable.ts"; +export { StatefulEvt } from "./StatefulEvt.ts"; +export { StatefulReadonlyEvt, StateDiff as Diff } from "./StatefulReadonlyEvt.ts"; +export { StatefulPostable } from "./StatefulPostable.ts"; +export { VoidCtx } from "./VoidCtx.ts"; +export { VoidEvt } from "./VoidEvt.ts"; \ No newline at end of file diff --git a/src/lib/types/lib.dom.ts b/lib/types/lib.dom.ts similarity index 100% rename from src/lib/types/lib.dom.ts rename to lib/types/lib.dom.ts diff --git a/src/lib/util/compose.ts b/lib/util/compose.ts similarity index 95% rename from src/lib/util/compose.ts rename to lib/util/compose.ts index d5707eb0..3f2a327d 100644 --- a/src/lib/util/compose.ts +++ b/lib/util/compose.ts @@ -1,9 +1,9 @@ -import { encapsulateOpState } from "./encapsulateOpState"; -import { invokeOperator } from "./invokeOperator"; -import { Operator } from "../types/Operator"; -import { id } from "../../tools/typeSafety/id"; -import { assert } from "../../tools/typeSafety/assert"; -import { typeGuard } from "../../tools/typeSafety/typeGuard"; +import { encapsulateOpState } from "./encapsulateOpState.ts"; +import { invokeOperator } from "./invokeOperator.ts"; +import { Operator } from "../types/Operator.ts"; +import { id } from "../../tools/typeSafety/id.ts"; +import { assert } from "../../tools/typeSafety/assert.ts"; +import { typeGuard } from "../../tools/typeSafety/typeGuard.ts"; function f_o_g( op1: Operator, diff --git a/src/lib/util/encapsulateOpState.ts b/lib/util/encapsulateOpState.ts similarity index 85% rename from src/lib/util/encapsulateOpState.ts rename to lib/util/encapsulateOpState.ts index 8cfb7776..ec8a972f 100644 --- a/src/lib/util/encapsulateOpState.ts +++ b/lib/util/encapsulateOpState.ts @@ -1,5 +1,5 @@ -import { id } from "../../tools/typeSafety/id"; -import { Operator } from "../types/Operator"; +import { id } from "../../tools/typeSafety/id.ts"; +import { Operator } from "../types/Operator.ts"; export function encapsulateOpState( statefulFλOp: Operator.fλ.Stateful diff --git a/src/lib/util/genericOperators/chunksOf.ts b/lib/util/genericOperators/chunksOf.ts similarity index 96% rename from src/lib/util/genericOperators/chunksOf.ts rename to lib/util/genericOperators/chunksOf.ts index 8cfdfdee..f5d603ee 100644 --- a/src/lib/util/genericOperators/chunksOf.ts +++ b/lib/util/genericOperators/chunksOf.ts @@ -1,5 +1,5 @@ -import { compose } from "../compose"; -import { concatUint8Array } from "../../../tools/concatUint8Array"; +import { compose } from "../compose.ts"; +import { concatUint8Array } from "../../../tools/concatUint8Array.ts"; /** Output Uint8Array of fixed size*/ export const chunksOf = (byteLength: number) => { diff --git a/lib/util/genericOperators/index.ts b/lib/util/genericOperators/index.ts new file mode 100644 index 00000000..72ada717 --- /dev/null +++ b/lib/util/genericOperators/index.ts @@ -0,0 +1,2 @@ +export { throttleTime } from "./throttleTime.ts"; +export { to } from "./to.ts"; \ No newline at end of file diff --git a/src/lib/util/genericOperators/scan.ts b/lib/util/genericOperators/scan.ts similarity index 88% rename from src/lib/util/genericOperators/scan.ts rename to lib/util/genericOperators/scan.ts index 1be88838..c5a19e87 100644 --- a/src/lib/util/genericOperators/scan.ts +++ b/lib/util/genericOperators/scan.ts @@ -1,4 +1,4 @@ -import { compose } from "../compose"; +import { compose } from "../compose.ts"; export const scan = ( accumulator: (acc: U, value: T, index: number) => U, diff --git a/src/lib/util/genericOperators/throttleTime.ts b/lib/util/genericOperators/throttleTime.ts similarity index 91% rename from src/lib/util/genericOperators/throttleTime.ts rename to lib/util/genericOperators/throttleTime.ts index 6e9c80c9..6a397dfd 100644 --- a/src/lib/util/genericOperators/throttleTime.ts +++ b/lib/util/genericOperators/throttleTime.ts @@ -1,4 +1,4 @@ -import { compose } from "../compose"; +import { compose } from "../compose.ts"; export const throttleTime = (duration: number) => compose( diff --git a/src/lib/util/genericOperators/to.ts b/lib/util/genericOperators/to.ts similarity index 84% rename from src/lib/util/genericOperators/to.ts rename to lib/util/genericOperators/to.ts index 2080aa0f..152e9b49 100644 --- a/src/lib/util/genericOperators/to.ts +++ b/lib/util/genericOperators/to.ts @@ -1,4 +1,4 @@ -import { Operator } from "../../types/Operator"; +import { Operator } from "../../types/Operator.ts"; export const to = ( eventName: K diff --git a/lib/util/index.ts b/lib/util/index.ts new file mode 100644 index 00000000..98e42588 --- /dev/null +++ b/lib/util/index.ts @@ -0,0 +1,3 @@ +export * from "./genericOperators/index.ts"; +export { compose } from "./compose.ts"; +export { invokeOperator } from "./invokeOperator.ts"; \ No newline at end of file diff --git a/src/lib/util/invokeOperator.ts b/lib/util/invokeOperator.ts similarity index 94% rename from src/lib/util/invokeOperator.ts rename to lib/util/invokeOperator.ts index 64d1a809..83dab337 100644 --- a/src/lib/util/invokeOperator.ts +++ b/lib/util/invokeOperator.ts @@ -1,5 +1,5 @@ -import { Operator } from "../types/Operator"; +import { Operator } from "../types/Operator.ts"; /** Invoke any type of stateless operator and return as if it was a fλ*/ export function invokeOperator(op: Operator.fλ.Stateless, data: T, isPost?: true): Operator.fλ.Result; diff --git a/mod.ts b/mod.ts new file mode 100644 index 00000000..cee578a4 --- /dev/null +++ b/mod.ts @@ -0,0 +1,2 @@ +//Automatically generated by denoify. It is important not to edit this file. +export * from "./lib/index.ts"; \ No newline at end of file diff --git a/src/lib/importProxy.ts b/src/lib/importProxy.ts deleted file mode 100644 index 55fc58ac..00000000 --- a/src/lib/importProxy.ts +++ /dev/null @@ -1,11 +0,0 @@ - - -/** Manually handling circular import so React Native does not gives warning. */ -export const importProxy: { - Ctx: typeof import("./Ctx").Ctx; - Evt: typeof import("./Evt").Evt; - StatefulEvt: typeof import("./StatefulEvt").StatefulEvt; -} = {} as any; - - - diff --git a/src/lib/index.ts b/src/lib/index.ts deleted file mode 100644 index 2b52c6c1..00000000 --- a/src/lib/index.ts +++ /dev/null @@ -1,9 +0,0 @@ - -export * from "./types"; -export * from "./util"; - -export { Ctx } from "./Ctx"; -export { Evt } from "./Evt"; -export { StatefulEvt } from "./StatefulEvt"; - -export { matchVoid } from "../tools/typeSafety/matchVoid"; diff --git a/src/lib/types/helper/index.ts b/src/lib/types/helper/index.ts deleted file mode 100644 index 1f485991..00000000 --- a/src/lib/types/helper/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export { FactorizeEvt } from "./FactorizeEvt"; -export { SwapEvtType } from "./SwapEvtType"; -export { ToPostableEvt } from "./ToPostableEvt"; -export { ToNonPostableEvt } from "./ToNonPostableEvt"; -export { UnpackCtx } from "./UnpackCtx"; -export { UnpackEvt, EvtLike } from "./UnpackEvt"; \ No newline at end of file diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts deleted file mode 100644 index 648d1b0f..00000000 --- a/src/lib/types/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from "./helper"; -export * from "./interfaces"; -export { EventTargetLike } from "./EventTargetLike"; -export { EvtError } from "./EvtError"; -export { Handler } from "./Handler"; -import * as dom from "./lib.dom"; export { dom }; -export { Operator } from "./Operator"; diff --git a/src/lib/types/interfaces/Evt.ts b/src/lib/types/interfaces/Evt.ts deleted file mode 100644 index f19cae5d..00000000 --- a/src/lib/types/interfaces/Evt.ts +++ /dev/null @@ -1,5 +0,0 @@ - -type Postable = import("./Postable").Postable; -type NonPostableEvt = import("./NonPostableEvt").NonPostableEvt; - -export interface Evt extends Postable, NonPostableEvt { } \ No newline at end of file diff --git a/src/lib/types/interfaces/StatefulEvt.ts b/src/lib/types/interfaces/StatefulEvt.ts deleted file mode 100644 index f0cf412f..00000000 --- a/src/lib/types/interfaces/StatefulEvt.ts +++ /dev/null @@ -1,10 +0,0 @@ - -type StatefulReadonlyEvt = import("./StatefulReadonlyEvt").StatefulReadonlyEvt; -type StatefulPostable = import("./StatefulPostable").StatefulPostable; - -export interface StatefulEvt extends StatefulReadonlyEvt, StatefulPostable { - - /** https://docs.evt.land/api/statefulevt#state */ - state: T; - -}; diff --git a/src/lib/types/interfaces/index.ts b/src/lib/types/interfaces/index.ts deleted file mode 100644 index 346fe450..00000000 --- a/src/lib/types/interfaces/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -export { Ctx, DoneOrAborted } from "./Ctx"; -export { CtxLike, VoidCtxLike } from "./CtxLike"; -export { Evt } from "./Evt"; -export { NonPostableEvt } from "./NonPostableEvt"; -export { Postable } from "./Postable"; -export { StatefulEvt } from "./StatefulEvt"; -export { StatefulReadonlyEvt, StateDiff as Diff } from "./StatefulReadonlyEvt"; -export { StatefulPostable } from "./StatefulPostable"; -export { VoidCtx } from "./VoidCtx"; -export { VoidEvt } from "./VoidEvt"; \ No newline at end of file diff --git a/src/lib/util/genericOperators/index.ts b/src/lib/util/genericOperators/index.ts deleted file mode 100644 index 1a77267d..00000000 --- a/src/lib/util/genericOperators/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { throttleTime } from "./throttleTime"; -export { to } from "./to"; \ No newline at end of file diff --git a/src/lib/util/index.ts b/src/lib/util/index.ts deleted file mode 100644 index adec13de..00000000 --- a/src/lib/util/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./genericOperators"; -export { compose } from "./compose"; -export { invokeOperator } from "./invokeOperator"; \ No newline at end of file diff --git a/src/test/deno_index.ts b/src/test/deno_index.ts deleted file mode 100644 index b8a01295..00000000 --- a/src/test/deno_index.ts +++ /dev/null @@ -1,94 +0,0 @@ - -import "../tools/reducers/test"; - -import "./test1"; -import "./test2"; -import "./test3"; -import "./test4"; - - - -import "./test8"; -import "./test9"; -import "./test10"; -import "./test11"; - - -import "./test14"; -import "./test15"; -import "./test16"; -import "./test17"; -import "./test18"; -import "./test19"; - -import "./test21"; -import "./test22"; - -import "./test24"; -import "./test25"; -import "./test26"; -import "./test27"; -import "./test28"; -import "./test29"; -import "./test30"; -import "./test31"; - -import "./test33"; -import "./test34"; -import "./test35"; -import "./test36"; -import "./test37"; -import "./test38"; -import "./test39"; - - - - -import "./test44"; - - - - -import "./test49"; -import "./test50"; -import "./test51"; -import "./test52"; //May fail if test ran of slow host. -import "./test53"; -import "./test54"; -import "./test55"; - - - -import "./test59"; -import "./test60"; -import "./test61"; -import "./test62"; - -import "./test64"; -import "./test65"; -import "./test66"; -import "./test67"; -import "./test68"; -import "./test69"; -import "./test70"; -import "./test71"; -import "./test72"; -import "./test73"; - - -import "./test76"; - - -import "./test78"; -import "./test79"; -import "./test80"; -import "./test81"; -import "./test82"; -import "./test83"; -import "./test84"; -import "./test85"; -import "./test86"; -import "./test87"; -import "./test88"; -import "./test89"; -import "./test90"; \ No newline at end of file diff --git a/src/test/test85.ts b/src/test/test85.ts deleted file mode 100644 index ea7655cf..00000000 --- a/src/test/test85.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Evt, Ctx } from "../lib"; -import { assert } from "../tools/typeSafety/assert"; - -assert(Evt.name === "Evt"); -assert(Ctx.name === "Ctx"); - -console.log("PASS"); \ No newline at end of file diff --git a/src/tools/inDepth/index.ts b/src/tools/inDepth/index.ts deleted file mode 100644 index f3a6f522..00000000 --- a/src/tools/inDepth/index.ts +++ /dev/null @@ -1,3 +0,0 @@ - -export * from "./same"; -export * from "./copy"; \ No newline at end of file diff --git a/src/tools/reducers/index.ts b/src/tools/reducers/index.ts deleted file mode 100644 index 0a04731a..00000000 --- a/src/tools/reducers/index.ts +++ /dev/null @@ -1,28 +0,0 @@ - -import { allEquals, allEqualsFactory } from "./allEquals"; -import { allEqualsTo, allEqualsToFactory } from "./allEqualsTo"; -import { allUniq, allUniqFactory } from "./allUniq"; -import { and } from "./and"; -import { includes } from "./includes"; -import { count } from "./count"; -import { every } from "./every"; -import { or } from "./or"; -import { removeDuplicates, removeDuplicatesFactory } from "./removeDuplicates"; -import { sameAs, sameAsFactory } from "./sameAs"; -import { partition } from "./partition"; -import { diff } from "./diff"; - -export { - allEquals, allEqualsFactory, - allEqualsTo, allEqualsToFactory, - allUniq, allUniqFactory, - and, - includes, - count, - every, - or, - removeDuplicates, removeDuplicatesFactory, - sameAs, sameAsFactory, - partition, - diff -}; diff --git a/src/tools/testing/index.ts b/src/tools/testing/index.ts deleted file mode 100644 index 2b4805f4..00000000 --- a/src/tools/testing/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./getPromiseAssertionApi"; \ No newline at end of file diff --git a/src/tools/typeSafety/index.ts b/src/tools/typeSafety/index.ts deleted file mode 100644 index 08534cd4..00000000 --- a/src/tools/typeSafety/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -export { assert } from "./assert"; -export { AsyncReturnType } from "./AsyncReturnType"; -export { exclude } from "./exclude"; -export { id } from "./id"; -export { matchVoid } from "./matchVoid"; -export { objectKeys } from "./objectKeys"; -export { typeGuard } from "./typeGuard"; -export { UnpackPromise } from "./UnpackPromise"; -export { UnpackTypeGuard } from "./UnpackTypeGuard"; \ No newline at end of file diff --git a/test/deno_index.ts b/test/deno_index.ts new file mode 100644 index 00000000..9361aeed --- /dev/null +++ b/test/deno_index.ts @@ -0,0 +1,94 @@ + +import "../tools/reducers/test.ts"; + +import "./test1.ts"; +import "./test2.ts"; +import "./test3.ts"; +import "./test4.ts"; + + + +import "./test8.ts"; +import "./test9.ts"; +import "./test10.ts"; +import "./test11.ts"; + + +import "./test14.ts"; +import "./test15.ts"; +import "./test16.ts"; +import "./test17.ts"; +import "./test18.ts"; +import "./test19.ts"; + +import "./test21.ts"; +import "./test22.ts"; + +import "./test24.ts"; +import "./test25.ts"; +import "./test26.ts"; +import "./test27.ts"; +import "./test28.ts"; +import "./test29.ts"; +import "./test30.ts"; +import "./test31.ts"; + +import "./test33.ts"; +import "./test34.ts"; +import "./test35.ts"; +import "./test36.ts"; +import "./test37.ts"; +import "./test38.ts"; +import "./test39.ts"; + + + + +import "./test44.ts"; + + + + +import "./test49.ts"; +import "./test50.ts"; +import "./test51.ts"; +import "./test52.ts"; //May fail if test ran of slow host. +import "./test53.ts"; +import "./test54.ts"; +import "./test55.ts"; + + + +import "./test59.ts"; +import "./test60.ts"; +import "./test61.ts"; +import "./test62.ts"; + +import "./test64.ts"; +import "./test65.ts"; +import "./test66.ts"; +import "./test67.ts"; +import "./test68.ts"; +import "./test69.ts"; +import "./test70.ts"; +import "./test71.ts"; +import "./test72.ts"; +import "./test73.ts"; + + +import "./test76.ts"; + + +import "./test78.ts"; +import "./test79.ts"; +import "./test80.ts"; +import "./test81.ts"; +import "./test82.ts"; +import "./test83.ts"; +import "./test84.ts"; +import "./test85.ts"; +import "./test86.ts"; +import "./test87.ts"; +import "./test88.ts"; +import "./test89.ts"; +import "./test90.ts"; \ No newline at end of file diff --git a/src/test/getHandlerPr.ts b/test/getHandlerPr.ts similarity index 71% rename from src/test/getHandlerPr.ts rename to test/getHandlerPr.ts index 9cce9f20..72b7d1cc 100644 --- a/src/test/getHandlerPr.ts +++ b/test/getHandlerPr.ts @@ -1,7 +1,7 @@ -import { NonPostableEvt } from "../lib"; -import { arrDiff } from "../tools/reducers/diff"; -import { assert } from "../tools/typeSafety"; +import { NonPostableEvt } from "../lib/index.ts"; +import { arrDiff } from "../tools/reducers/diff.ts"; +import { assert } from "../tools/typeSafety/index.ts"; /** For tests that used the legacy attach returned Promise */ export function getHandlerPr(evt: NonPostableEvt, run: ()=> void): Promise{ diff --git a/src/test/index.ts b/test/index.ts similarity index 72% rename from src/test/index.ts rename to test/index.ts index 43b40569..4ac80309 100644 --- a/src/test/index.ts +++ b/test/index.ts @@ -1,3 +1,10 @@ +const __dirname = (()=>{ + const {url: urlStr}= import.meta; + const url= new URL(urlStr); + const __filename = url.protocol === "file:" ? url.pathname : urlStr; + return __filename.replace(/[/][^/]*$/, ''); +})(); + process.once("unhandledRejection", error => { @@ -10,8 +17,8 @@ console.assert = (condition: any, msg?: string) => { } }; -import { existsSync } from "fs"; -import { join } from "path"; +import { existsSync } from "https://deno.land/std/node/fs.ts"; +import { join } from "https://deno.land/std/node/path.ts"; (async ()=>{ diff --git a/src/test/test1.ts b/test/test1.ts similarity index 87% rename from src/test/test1.ts rename to test/test1.ts index 356a42d2..f20914c2 100644 --- a/src/test/test1.ts +++ b/test/test1.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib/index"; +import { Evt } from "../lib/index.ts"; let evt = new Evt(); diff --git a/src/test/test10.ts b/test/test10.ts similarity index 90% rename from src/test/test10.ts rename to test/test10.ts index 63fdc8d1..249653e5 100644 --- a/src/test/test10.ts +++ b/test/test10.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib/index"; +import { Evt } from "../lib/index.ts"; let evt = Evt.create(); diff --git a/src/test/test11.ts b/test/test11.ts similarity index 92% rename from src/test/test11.ts rename to test/test11.ts index 6d0de289..ece2c389 100644 --- a/src/test/test11.ts +++ b/test/test11.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let evt = Evt.create(); diff --git a/src/test/test12.ts b/test/test12.ts similarity index 88% rename from src/test/test12.ts rename to test/test12.ts index dd418e38..5916143d 100644 --- a/src/test/test12.ts +++ b/test/test12.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let evt = Evt.create(); diff --git a/src/test/test13.ts b/test/test13.ts similarity index 94% rename from src/test/test13.ts rename to test/test13.ts index 1122eac1..bad71299 100644 --- a/src/test/test13.ts +++ b/test/test13.ts @@ -1,6 +1,6 @@ import { Evt, EvtError -} from "../lib/index"; +} from "../lib/index.ts"; let pass= false; diff --git a/src/test/test14.ts b/test/test14.ts similarity index 92% rename from src/test/test14.ts rename to test/test14.ts index 448bb0e4..93302f14 100644 --- a/src/test/test14.ts +++ b/test/test14.ts @@ -1,5 +1,5 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let success= false; diff --git a/src/test/test15.ts b/test/test15.ts similarity index 98% rename from src/test/test15.ts rename to test/test15.ts index b701d6fd..0aad5a60 100644 --- a/src/test/test15.ts +++ b/test/test15.ts @@ -1,6 +1,6 @@ import { Evt -} from "../lib/index"; +} from "../lib/index.ts"; let evt = new Evt(); diff --git a/src/test/test16.ts b/test/test16.ts similarity index 97% rename from src/test/test16.ts rename to test/test16.ts index 33c706b4..0f6919c3 100644 --- a/src/test/test16.ts +++ b/test/test16.ts @@ -1,6 +1,6 @@ import { Evt -} from "../lib/index"; +} from "../lib/index.ts"; interface Animal { type: "CAT" | "SPIDER"; diff --git a/src/test/test17.ts b/test/test17.ts similarity index 96% rename from src/test/test17.ts rename to test/test17.ts index ca75d27e..1d78c52a 100644 --- a/src/test/test17.ts +++ b/test/test17.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib/index"; +import { Evt } from "../lib/index.ts"; interface Animal { type: "CAT" | "SPIDER"; diff --git a/src/test/test18.ts b/test/test18.ts similarity index 92% rename from src/test/test18.ts rename to test/test18.ts index 027dde41..439fbbb4 100644 --- a/src/test/test18.ts +++ b/test/test18.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let count= 0; diff --git a/src/test/test19.ts b/test/test19.ts similarity index 87% rename from src/test/test19.ts rename to test/test19.ts index 2b6f0ad3..c8571f97 100644 --- a/src/test/test19.ts +++ b/test/test19.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let evt = new Evt<{ init: boolean}>(); diff --git a/src/test/test2.ts b/test/test2.ts similarity index 94% rename from src/test/test2.ts rename to test/test2.ts index fc7fe7fc..cd985de0 100644 --- a/src/test/test2.ts +++ b/test/test2.ts @@ -1,4 +1,4 @@ -import { Evt, Ctx } from "../lib/index"; +import { Evt, Ctx } from "../lib/index.ts"; type T = string; diff --git a/src/test/test20.ts b/test/test20.ts similarity index 84% rename from src/test/test20.ts rename to test/test20.ts index 3b467dee..d209fd54 100644 --- a/src/test/test20.ts +++ b/test/test20.ts @@ -1,4 +1,4 @@ -import { Evt, EvtError } from "../lib"; +import { Evt, EvtError } from "../lib/index.ts"; let evt= new Evt(); diff --git a/src/test/test21.ts b/test/test21.ts similarity index 86% rename from src/test/test21.ts rename to test/test21.ts index 65c1d9f5..2d8b697d 100644 --- a/src/test/test21.ts +++ b/test/test21.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let evt= new Evt(); diff --git a/src/test/test22.ts b/test/test22.ts similarity index 93% rename from src/test/test22.ts rename to test/test22.ts index 6907a15f..6a5c3ab2 100644 --- a/src/test/test22.ts +++ b/test/test22.ts @@ -1,7 +1,7 @@ -import { Evt } from "../lib"; -import { getPromiseAssertionApi } from "../tools/testing"; -import {getHandlerPr } from "./getHandlerPr"; +import { Evt } from "../lib/index.ts"; +import { getPromiseAssertionApi } from "../tools/testing/index.ts"; +import {getHandlerPr } from "./getHandlerPr.ts"; const { mustResolve, mustReject } = getPromiseAssertionApi(); let op = (object: Object): object is Array => object instanceof Array; diff --git a/src/test/test23.ts b/test/test23.ts similarity index 80% rename from src/test/test23.ts rename to test/test23.ts index 9673e1c9..54dea691 100644 --- a/src/test/test23.ts +++ b/test/test23.ts @@ -1,5 +1,5 @@ -import { Evt } from "../lib"; -import { EventEmitter } from "events"; +import { Evt } from "../lib/index.ts"; +import { EventEmitter } from "https://deno.land/std/node/events.ts"; let success = 0; diff --git a/src/test/test24.ts b/test/test24.ts similarity index 83% rename from src/test/test24.ts rename to test/test24.ts index 46156e45..cb10084e 100644 --- a/src/test/test24.ts +++ b/test/test24.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let evt= new Evt(); diff --git a/src/test/test25.ts b/test/test25.ts similarity index 86% rename from src/test/test25.ts rename to test/test25.ts index 1dd50463..70f654d7 100644 --- a/src/test/test25.ts +++ b/test/test25.ts @@ -1,4 +1,4 @@ -import { Evt, EvtError } from "../lib"; +import { Evt, EvtError } from "../lib/index.ts"; let evt = new Evt(); diff --git a/src/test/test26.ts b/test/test26.ts similarity index 78% rename from src/test/test26.ts rename to test/test26.ts index d182599c..9c72a87e 100644 --- a/src/test/test26.ts +++ b/test/test26.ts @@ -1,7 +1,7 @@ -import { Evt } from "../lib"; -import { UnpackEvt, ToNonPostableEvt } from "../lib/types/helper"; -type UnpackEvt_ = import("../lib/types/helper").UnpackEvt; +import { Evt } from "../lib/index.ts"; +import { UnpackEvt, ToNonPostableEvt } from "../lib/types/helper/index.ts"; +type UnpackEvt_ = import("../lib/types/helper/index.ts").UnpackEvt; { diff --git a/src/test/test27.ts b/test/test27.ts similarity index 82% rename from src/test/test27.ts rename to test/test27.ts index cd3dede3..fcf817d2 100644 --- a/src/test/test27.ts +++ b/test/test27.ts @@ -1,5 +1,5 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let evt = new Evt(); diff --git a/src/test/test28.ts b/test/test28.ts similarity index 86% rename from src/test/test28.ts rename to test/test28.ts index aa8377b2..6ea1757c 100644 --- a/src/test/test28.ts +++ b/test/test28.ts @@ -1,5 +1,5 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let evt = new Evt(); diff --git a/src/test/test29.ts b/test/test29.ts similarity index 87% rename from src/test/test29.ts rename to test/test29.ts index d10c237e..940dc57f 100644 --- a/src/test/test29.ts +++ b/test/test29.ts @@ -1,5 +1,5 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let evt = new Evt(); diff --git a/src/test/test3.ts b/test/test3.ts similarity index 90% rename from src/test/test3.ts rename to test/test3.ts index f43a102e..bc9c976d 100644 --- a/src/test/test3.ts +++ b/test/test3.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib/index"; +import { Evt } from "../lib/index.ts"; type T= string; diff --git a/src/test/test30.ts b/test/test30.ts similarity index 91% rename from src/test/test30.ts rename to test/test30.ts index 894c837e..775d7be7 100644 --- a/src/test/test30.ts +++ b/test/test30.ts @@ -1,5 +1,5 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; let evt = new Evt(); diff --git a/src/test/test31.ts b/test/test31.ts similarity index 86% rename from src/test/test31.ts rename to test/test31.ts index f26725e4..423e7de7 100644 --- a/src/test/test31.ts +++ b/test/test31.ts @@ -1,5 +1,5 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; const evtText = new Evt(); diff --git a/src/test/test32.ts b/test/test32.ts similarity index 100% rename from src/test/test32.ts rename to test/test32.ts diff --git a/src/test/test33.ts b/test/test33.ts similarity index 94% rename from src/test/test33.ts rename to test/test33.ts index ff9bde02..bc53126f 100644 --- a/src/test/test33.ts +++ b/test/test33.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; type Circle = { type: "CIRCLE"; diff --git a/src/test/test34.ts b/test/test34.ts similarity index 80% rename from src/test/test34.ts rename to test/test34.ts index f5d51ceb..401960d9 100644 --- a/src/test/test34.ts +++ b/test/test34.ts @@ -1,7 +1,7 @@ -import { exclude } from "../tools/typeSafety/exclude"; -import { same } from "../tools/inDepth"; -import { assert } from "../tools/typeSafety/assert" +import { exclude } from "../tools/typeSafety/exclude.ts"; +import { same } from "../tools/inDepth/index.ts"; +import { assert } from "../tools/typeSafety/assert.ts" { diff --git a/src/test/test35.ts b/test/test35.ts similarity index 97% rename from src/test/test35.ts rename to test/test35.ts index 8c419690..f5d3d099 100644 --- a/src/test/test35.ts +++ b/test/test35.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { id, assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { id, assert } from "../tools/typeSafety/index.ts"; type Circle = { type: "CIRCLE"; diff --git a/src/test/test36.ts b/test/test36.ts similarity index 83% rename from src/test/test36.ts rename to test/test36.ts index df9717ab..0b078269 100644 --- a/src/test/test36.ts +++ b/test/test36.ts @@ -1,5 +1,5 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; const evt= Evt.create(); diff --git a/src/test/test37.ts b/test/test37.ts similarity index 97% rename from src/test/test37.ts rename to test/test37.ts index 5752196c..516bf450 100644 --- a/src/test/test37.ts +++ b/test/test37.ts @@ -1,8 +1,8 @@ -import { Evt } from "../lib"; -//import { Evt as EvtNext } from "../lib/Evt"; -import { id } from "../tools/typeSafety"; -import { getPromiseAssertionApi } from "../tools/testing"; -import { getHandlerPr } from "./getHandlerPr"; +import { Evt } from "../lib/index.ts"; +//import { Evt as EvtNext } from "../lib/Evt.ts"; +import { id } from "../tools/typeSafety/index.ts"; +import { getPromiseAssertionApi } from "../tools/testing/index.ts"; +import { getHandlerPr } from "./getHandlerPr.ts"; const { mustResolve, mustStayPending } = getPromiseAssertionApi(); diff --git a/src/test/test38.ts b/test/test38.ts similarity index 97% rename from src/test/test38.ts rename to test/test38.ts index 5484b151..0baa95fa 100644 --- a/src/test/test38.ts +++ b/test/test38.ts @@ -1,7 +1,7 @@ //NOTE: This test do not perform any actual check at runtime. -import { Evt } from "../lib"; -import { getHandlerPr } from "./getHandlerPr"; +import { Evt } from "../lib/index.ts"; +import { getHandlerPr } from "./getHandlerPr.ts"; type Circle = { type: "CIRCLE"; diff --git a/src/test/test39.ts b/test/test39.ts similarity index 97% rename from src/test/test39.ts rename to test/test39.ts index 9510615a..fb4b6e36 100644 --- a/src/test/test39.ts +++ b/test/test39.ts @@ -1,6 +1,6 @@ -import { Evt, ToNonPostableEvt } from "../lib"; -import { id, assert } from "../tools/typeSafety"; +import { Evt, ToNonPostableEvt } from "../lib/index.ts"; +import { id, assert } from "../tools/typeSafety/index.ts"; type Person = { name: string; diff --git a/src/test/test4.ts b/test/test4.ts similarity index 88% rename from src/test/test4.ts rename to test/test4.ts index f13be434..5b6f53fe 100644 --- a/src/test/test4.ts +++ b/test/test4.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib/index"; +import { Evt } from "../lib/index.ts"; type T= string; diff --git a/src/test/test44.ts b/test/test44.ts similarity index 88% rename from src/test/test44.ts rename to test/test44.ts index cbd4939d..ab818a09 100644 --- a/src/test/test44.ts +++ b/test/test44.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; const evtText = new Evt<"TICK" | "END" >(); diff --git a/src/test/test49.ts b/test/test49.ts similarity index 87% rename from src/test/test49.ts rename to test/test49.ts index 47fe70d3..0ec36497 100644 --- a/src/test/test49.ts +++ b/test/test49.ts @@ -1,9 +1,9 @@ -import { Evt, Handler, Ctx } from "../lib"; -import { assert } from "../tools/typeSafety"; -import { getPromiseAssertionApi } from "../tools/testing"; -import { sameFactory } from "../tools/inDepth"; -import { getHandlerPr } from "./getHandlerPr"; +import { Evt, Handler, Ctx } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; +import { getPromiseAssertionApi } from "../tools/testing/index.ts"; +import { sameFactory } from "../tools/inDepth/index.ts"; +import { getHandlerPr } from "./getHandlerPr.ts"; const { same } = sameFactory({ "takeIntoAccountArraysOrdering": false }); diff --git a/src/test/test5.ts b/test/test5.ts similarity index 90% rename from src/test/test5.ts rename to test/test5.ts index 0148b0cc..9bc89052 100644 --- a/src/test/test5.ts +++ b/test/test5.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib/index"; +import { Evt } from "../lib/index.ts"; let evt = new Evt(); diff --git a/src/test/test50.ts b/test/test50.ts similarity index 71% rename from src/test/test50.ts rename to test/test50.ts index 758272a4..934b9174 100644 --- a/src/test/test50.ts +++ b/test/test50.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const evtAge = new Evt(); diff --git a/src/test/test51.ts b/test/test51.ts similarity index 93% rename from src/test/test51.ts rename to test/test51.ts index b81ed7e8..e8b723f9 100644 --- a/src/test/test51.ts +++ b/test/test51.ts @@ -1,9 +1,9 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety/assert"; -import { scan } from "../lib/util/genericOperators/scan"; -import { getHandlerPr } from "./getHandlerPr"; -import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/assert.ts"; +import { scan } from "../lib/util/genericOperators/scan.ts"; +import { getHandlerPr } from "./getHandlerPr.ts"; +import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi.ts"; const { mustResolve, mustStayPending } = getPromiseAssertionApi({ "takeIntoAccountArraysOrdering": true }); diff --git a/src/test/test52.ts b/test/test52.ts similarity index 82% rename from src/test/test52.ts rename to test/test52.ts index 03832784..02d94773 100644 --- a/src/test/test52.ts +++ b/test/test52.ts @@ -1,6 +1,6 @@ -import { Evt, throttleTime } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt, throttleTime } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const evtCount = new Evt(); diff --git a/src/test/test53.ts b/test/test53.ts similarity index 67% rename from src/test/test53.ts rename to test/test53.ts index b094d363..7edf4e04 100644 --- a/src/test/test53.ts +++ b/test/test53.ts @@ -1,8 +1,8 @@ -import { Evt, Handler } from "../lib"; -import { assert } from "../tools/typeSafety"; -import { getHandlerPr } from "./getHandlerPr"; -import { getPromiseAssertionApi } from "../tools/testing"; +import { Evt, Handler } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; +import { getHandlerPr } from "./getHandlerPr.ts"; +import { getPromiseAssertionApi } from "../tools/testing/index.ts"; const { mustResolve } = getPromiseAssertionApi(); diff --git a/src/test/test54.ts b/test/test54.ts similarity index 74% rename from src/test/test54.ts rename to test/test54.ts index 36ba2fc9..1f7c0ce2 100644 --- a/src/test/test54.ts +++ b/test/test54.ts @@ -1,5 +1,5 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const evtText = new Evt(); diff --git a/src/test/test55.ts b/test/test55.ts similarity index 95% rename from src/test/test55.ts rename to test/test55.ts index 25fce380..56274fca 100644 --- a/src/test/test55.ts +++ b/test/test55.ts @@ -1,7 +1,7 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety"; -import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; +import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi.ts"; (async () => { diff --git a/src/test/test56.ts b/test/test56.ts similarity index 83% rename from src/test/test56.ts rename to test/test56.ts index 10a7ec71..a00b1b90 100644 --- a/src/test/test56.ts +++ b/test/test56.ts @@ -1,8 +1,8 @@ -import { Evt } from "../lib"; -import { EventEmitter } from "events"; -import { getPromiseAssertionApi } from "../tools/testing"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { EventEmitter } from "https://deno.land/std/node/events.ts"; +import { getPromiseAssertionApi } from "../tools/testing/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; (async () => { diff --git a/src/test/test57.ts b/test/test57.ts similarity index 82% rename from src/test/test57.ts rename to test/test57.ts index fdadfe0f..4c5e56c4 100644 --- a/src/test/test57.ts +++ b/test/test57.ts @@ -1,7 +1,7 @@ -import { Evt } from "../lib"; -import { Subject } from "rxjs"; -import { getPromiseAssertionApi } from "../tools/testing"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { Subject } from "rxjs DENOIFY: DEPENDENCY UNMET (DEV DEPENDENCY)"; +import { getPromiseAssertionApi } from "../tools/testing/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; (async () => { diff --git a/src/test/test59.ts b/test/test59.ts similarity index 92% rename from src/test/test59.ts rename to test/test59.ts index cd1517a5..de169dc5 100644 --- a/src/test/test59.ts +++ b/test/test59.ts @@ -1,6 +1,6 @@ -import { Evt, to, dom } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt, to, dom } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const evt = new Evt< ["text", string] | diff --git a/src/test/test6.ts b/test/test6.ts similarity index 92% rename from src/test/test6.ts rename to test/test6.ts index 1c066d1a..6ca591bb 100644 --- a/src/test/test6.ts +++ b/test/test6.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib/index"; +import { Evt } from "../lib/index.ts"; let evt = new Evt(); diff --git a/src/test/test60.ts b/test/test60.ts similarity index 78% rename from src/test/test60.ts rename to test/test60.ts index d4d74850..82ff6394 100644 --- a/src/test/test60.ts +++ b/test/test60.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const obj1: never[] = [] as any; const obj2 = {}; diff --git a/src/test/test61.ts b/test/test61.ts similarity index 82% rename from src/test/test61.ts rename to test/test61.ts index 0d67163a..240e8219 100644 --- a/src/test/test61.ts +++ b/test/test61.ts @@ -1,7 +1,7 @@ -import { Evt } from "../lib"; -import { getHandlerPr } from "./getHandlerPr"; -import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { getHandlerPr } from "./getHandlerPr.ts"; +import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const { mustResolve, mustReject } = getPromiseAssertionApi(); diff --git a/src/test/test62.ts b/test/test62.ts similarity index 94% rename from src/test/test62.ts rename to test/test62.ts index 683e7713..72c43795 100644 --- a/src/test/test62.ts +++ b/test/test62.ts @@ -1,14 +1,14 @@ -import { Evt, VoidEvt, EvtError } from "../lib"; -import { id, assert } from "../tools/typeSafety"; -import { every } from "../tools/reducers"; -import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi"; -import { concatUint8Array } from "../tools/concatUint8Array"; +import { Evt, VoidEvt, EvtError } from "../lib/index.ts"; +import { id, assert } from "../tools/typeSafety/index.ts"; +import { every } from "../tools/reducers/index.ts"; +import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi.ts"; +import { concatUint8Array } from "../tools/concatUint8Array.ts"; //const { mustReject, mustResolve } = getPromiseAssertionApi(); const { mustResolve, mustReject } = getPromiseAssertionApi({ "takeIntoAccountArraysOrdering": true }); -//import { Operator } from "../lib/types/Operator"; +//import { Operator } from "../lib/types/Operator.ts"; const MESSAGE_TOO_MUCH_BYTES = "Received to much data"; const MESSAGE_CANCEL = "Download canceled by user"; diff --git a/src/test/test63.ts b/test/test63.ts similarity index 94% rename from src/test/test63.ts rename to test/test63.ts index b1677fc6..394fb230 100644 --- a/src/test/test63.ts +++ b/test/test63.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { EventEmitter } from "events"; -import { assert } from "../tools/typeSafety/assert"; +import { Evt } from "../lib/index.ts"; +import { EventEmitter } from "https://deno.land/std/node/events.ts"; +import { assert } from "../tools/typeSafety/assert.ts"; const log = global.console.log; diff --git a/src/test/test64.ts b/test/test64.ts similarity index 74% rename from src/test/test64.ts rename to test/test64.ts index 005200b5..c030e07b 100644 --- a/src/test/test64.ts +++ b/test/test64.ts @@ -1,9 +1,9 @@ -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; -import { chunksOf } from "../lib/util/genericOperators/chunksOf"; -import { same } from "../tools/inDepth"; -import { assert } from "../tools/typeSafety" +import { chunksOf } from "../lib/util/genericOperators/chunksOf.ts"; +import { same } from "../tools/inDepth/index.ts"; +import { assert } from "../tools/typeSafety/index.ts" { diff --git a/src/test/test65.ts b/test/test65.ts similarity index 93% rename from src/test/test65.ts rename to test/test65.ts index 3d243d14..d054a90f 100644 --- a/src/test/test65.ts +++ b/test/test65.ts @@ -1,6 +1,6 @@ -import { Evt, throttleTime } from "../lib"; -import * as dom from "../lib/types/lib.dom"; +import { Evt, throttleTime } from "../lib/index.ts"; +import * as dom from "../lib/types/lib.dom.ts"; declare const document: dom.Document; diff --git a/src/test/test66.ts b/test/test66.ts similarity index 84% rename from src/test/test66.ts rename to test/test66.ts index d77581f6..53617c5d 100644 --- a/src/test/test66.ts +++ b/test/test66.ts @@ -1,8 +1,8 @@ -import { Evt } from "../lib"; -import { getHandlerPr } from "./getHandlerPr"; -import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi"; +import { Evt } from "../lib/index.ts"; +import { getHandlerPr } from "./getHandlerPr.ts"; +import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi.ts"; const { mustStayPending } = getPromiseAssertionApi(); diff --git a/src/test/test67.ts b/test/test67.ts similarity index 93% rename from src/test/test67.ts rename to test/test67.ts index 79facc2d..12e358ea 100644 --- a/src/test/test67.ts +++ b/test/test67.ts @@ -1,7 +1,7 @@ -import { Evt, compose } from "../lib"; -import { assert } from "../tools/typeSafety"; -import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi"; -import { getHandlerPr } from "./getHandlerPr"; +import { Evt, compose } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; +import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi.ts"; +import { getHandlerPr } from "./getHandlerPr.ts"; const { mustResolve, mustStayPending } = getPromiseAssertionApi(); diff --git a/src/test/test68.ts b/test/test68.ts similarity index 94% rename from src/test/test68.ts rename to test/test68.ts index acbd3191..e4b31e07 100644 --- a/src/test/test68.ts +++ b/test/test68.ts @@ -1,5 +1,5 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety/assert"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/assert.ts"; let warn_str = ""; diff --git a/src/test/test69.ts b/test/test69.ts similarity index 80% rename from src/test/test69.ts rename to test/test69.ts index ddd00474..979ad883 100644 --- a/src/test/test69.ts +++ b/test/test69.ts @@ -1,5 +1,5 @@ //NOTE: Only test type -import { Evt } from "../lib"; +import { Evt } from "../lib/index.ts"; const ctx= Evt.newCtx(); diff --git a/src/test/test7.ts b/test/test7.ts similarity index 88% rename from src/test/test7.ts rename to test/test7.ts index b0d0ab41..fabaddac 100644 --- a/src/test/test7.ts +++ b/test/test7.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib/index"; +import { Evt } from "../lib/index.ts"; let evt = new Evt(); diff --git a/src/test/test70.ts b/test/test70.ts similarity index 98% rename from src/test/test70.ts rename to test/test70.ts index 31674b37..eeb4c298 100644 --- a/src/test/test70.ts +++ b/test/test70.ts @@ -1,4 +1,4 @@ -import { Evt, VoidEvt, UnpackCtx, UnpackEvt, Ctx, VoidCtx } from "../lib"; +import { Evt, VoidEvt, UnpackCtx, UnpackEvt, Ctx, VoidCtx } from "../lib/index.ts"; const evtText= new Evt(); diff --git a/src/test/test71.ts b/test/test71.ts similarity index 82% rename from src/test/test71.ts rename to test/test71.ts index c0d475f3..fa055ee8 100644 --- a/src/test/test71.ts +++ b/test/test71.ts @@ -1,7 +1,7 @@ -import { Evt } from "../lib"; -import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi"; -import { getHandlerPr } from "./getHandlerPr"; +import { Evt } from "../lib/index.ts"; +import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi.ts"; +import { getHandlerPr } from "./getHandlerPr.ts"; const { mustResolve } = getPromiseAssertionApi(); diff --git a/src/test/test72.ts b/test/test72.ts similarity index 91% rename from src/test/test72.ts rename to test/test72.ts index ed0eb78f..88097b0f 100644 --- a/src/test/test72.ts +++ b/test/test72.ts @@ -1,9 +1,9 @@ -import { Evt, UnpackEvt } from "../lib"; -import { UnpackPromise } from "../tools/typeSafety"; +import { Evt, UnpackEvt } from "../lib/index.ts"; +import { UnpackPromise } from "../tools/typeSafety/index.ts"; -import { assert } from "../tools/typeSafety/assert"; -import { same } from "../tools/inDepth"; +import { assert } from "../tools/typeSafety/assert.ts"; +import { same } from "../tools/inDepth/index.ts"; { diff --git a/src/test/test73.ts b/test/test73.ts similarity index 97% rename from src/test/test73.ts rename to test/test73.ts index 4887e844..23caaf96 100644 --- a/src/test/test73.ts +++ b/test/test73.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety/assert"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/assert.ts"; { diff --git a/src/test/test76.ts b/test/test76.ts similarity index 90% rename from src/test/test76.ts rename to test/test76.ts index 6eb1457d..055dc9ea 100644 --- a/src/test/test76.ts +++ b/test/test76.ts @@ -1,8 +1,8 @@ -import { Evt } from "../lib"; -import * as inDepth from "../tools/inDepth"; -import { diff } from "../tools/reducers"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import * as inDepth from "../tools/inDepth/index.ts"; +import { diff } from "../tools/reducers/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; { diff --git a/src/test/test78.ts b/test/test78.ts similarity index 95% rename from src/test/test78.ts rename to test/test78.ts index c6ef5286..84ef9faa 100644 --- a/src/test/test78.ts +++ b/test/test78.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi"; +import { Evt } from "../lib/index.ts"; +import { getPromiseAssertionApi } from "../tools/testing/getPromiseAssertionApi.ts"; const { mustResolve, mustStayPending } = getPromiseAssertionApi(); diff --git a/src/test/test79.ts b/test/test79.ts similarity index 78% rename from src/test/test79.ts rename to test/test79.ts index c70912ab..d3ae918a 100644 --- a/src/test/test79.ts +++ b/test/test79.ts @@ -1,5 +1,5 @@ -import { Evt, StatefulReadonlyEvt } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt, StatefulReadonlyEvt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const evtCount = Evt.create(0); diff --git a/src/test/test8.ts b/test/test8.ts similarity index 97% rename from src/test/test8.ts rename to test/test8.ts index dcce400e..ab4cb9cd 100644 --- a/src/test/test8.ts +++ b/test/test8.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib/index"; +import { Evt } from "../lib/index.ts"; export interface Person { name: string; diff --git a/src/test/test80.ts b/test/test80.ts similarity index 72% rename from src/test/test80.ts rename to test/test80.ts index d8896a8c..ec88237b 100644 --- a/src/test/test80.ts +++ b/test/test80.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety/assert"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/assert.ts"; const evtClick = Evt.create(); diff --git a/src/test/test81.ts b/test/test81.ts similarity index 96% rename from src/test/test81.ts rename to test/test81.ts index 53f0502b..92b6407e 100644 --- a/src/test/test81.ts +++ b/test/test81.ts @@ -1,5 +1,5 @@ //NOTE: Type only -import { Evt, StatefulEvt, ToPostableEvt, ToNonPostableEvt, VoidEvt, NonPostableEvt, StatefulReadonlyEvt } from "../lib"; +import { Evt, StatefulEvt, ToPostableEvt, ToNonPostableEvt, VoidEvt, NonPostableEvt, StatefulReadonlyEvt } from "../lib/index.ts"; { diff --git a/src/test/test82.ts b/test/test82.ts similarity index 96% rename from src/test/test82.ts rename to test/test82.ts index 66fd8f6c..a142092b 100644 --- a/src/test/test82.ts +++ b/test/test82.ts @@ -1,5 +1,5 @@ //NOTE: Test type only -import { Evt, StatefulEvt, StatefulReadonlyEvt, NonPostableEvt, SwapEvtType, VoidEvt } from "../lib"; +import { Evt, StatefulEvt, StatefulReadonlyEvt, NonPostableEvt, SwapEvtType, VoidEvt } from "../lib/index.ts"; type A = SwapEvtType, void>; const a: VoidEvt = null as any as A;a; diff --git a/src/test/test83.ts b/test/test83.ts similarity index 74% rename from src/test/test83.ts rename to test/test83.ts index 6ec8874a..1e0a0c84 100644 --- a/src/test/test83.ts +++ b/test/test83.ts @@ -1,6 +1,6 @@ -import { Evt, VoidEvt, matchVoid } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt, VoidEvt, matchVoid } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const voidEvt = Evt.create(); diff --git a/src/test/test84.ts b/test/test84.ts similarity index 86% rename from src/test/test84.ts rename to test/test84.ts index cd84fc40..f2186349 100644 --- a/src/test/test84.ts +++ b/test/test84.ts @@ -1,6 +1,6 @@ //NOTE: type only -import { UnpackEvt, Evt } from "../lib"; +import { UnpackEvt, Evt } from "../lib/index.ts"; type A= UnpackEvt>; const a: number | void = null as any as A; a; diff --git a/test/test85.ts b/test/test85.ts new file mode 100644 index 00000000..5a8e17c7 --- /dev/null +++ b/test/test85.ts @@ -0,0 +1,7 @@ +import { Evt, Ctx } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/assert.ts"; + +assert(Evt.name === "Evt"); +assert(Ctx.name === "Ctx"); + +console.log("PASS"); \ No newline at end of file diff --git a/src/test/test86.ts b/test/test86.ts similarity index 86% rename from src/test/test86.ts rename to test/test86.ts index f4ea24c5..03270e1c 100644 --- a/src/test/test86.ts +++ b/test/test86.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety/assert"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/assert.ts"; let std_out = ""; diff --git a/src/test/test87.ts b/test/test87.ts similarity index 83% rename from src/test/test87.ts rename to test/test87.ts index 36039d9f..cd0ad9b5 100644 --- a/src/test/test87.ts +++ b/test/test87.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import {assert} from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import {assert} from "../tools/typeSafety/index.ts"; const evtIsBlue= Evt.create(false); const evtIsBig= Evt.create(false); diff --git a/src/test/test88.ts b/test/test88.ts similarity index 68% rename from src/test/test88.ts rename to test/test88.ts index 02ec4c92..0566c9c7 100644 --- a/src/test/test88.ts +++ b/test/test88.ts @@ -1,7 +1,7 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const evtText = Evt.create("foo"); diff --git a/src/test/test89.ts b/test/test89.ts similarity index 82% rename from src/test/test89.ts rename to test/test89.ts index a14a41da..992da05f 100644 --- a/src/test/test89.ts +++ b/test/test89.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const evtText= Evt.create("foo"); diff --git a/src/test/test9.ts b/test/test9.ts similarity index 98% rename from src/test/test9.ts rename to test/test9.ts index f8ffcde3..4ac697fc 100644 --- a/src/test/test9.ts +++ b/test/test9.ts @@ -1,4 +1,4 @@ -import { Evt } from "../lib/index"; +import { Evt } from "../lib/index.ts"; export interface Person { name: string; diff --git a/src/test/test90.ts b/test/test90.ts similarity index 86% rename from src/test/test90.ts rename to test/test90.ts index a7f4a517..b6698aa9 100644 --- a/src/test/test90.ts +++ b/test/test90.ts @@ -1,6 +1,6 @@ -import { Evt } from "../lib"; -import { assert } from "../tools/typeSafety"; +import { Evt } from "../lib/index.ts"; +import { assert } from "../tools/typeSafety/index.ts"; const evtText = Evt.create("foo"); diff --git a/src/tools/Deferred.ts b/tools/Deferred.ts similarity index 98% rename from src/tools/Deferred.ts rename to tools/Deferred.ts index 3363c78d..714d4521 100644 --- a/src/tools/Deferred.ts +++ b/tools/Deferred.ts @@ -1,5 +1,5 @@ -import { overwriteReadonlyProp } from "./typeSafety/overwriteReadonlyProp"; +import { overwriteReadonlyProp } from "./typeSafety/overwriteReadonlyProp.ts"; export class Deferred { diff --git a/src/tools/concatUint8Array.ts b/tools/concatUint8Array.ts similarity index 100% rename from src/tools/concatUint8Array.ts rename to tools/concatUint8Array.ts diff --git a/src/tools/inDepth/copy.ts b/tools/inDepth/copy.ts similarity index 90% rename from src/tools/inDepth/copy.ts rename to tools/inDepth/copy.ts index 6a0d6770..a0a68b03 100644 --- a/src/tools/inDepth/copy.ts +++ b/tools/inDepth/copy.ts @@ -1,9 +1,9 @@ -import { assert } from "../typeSafety/assert"; -import { Polyfill as Map, LightMap } from "minimal-polyfills/Map"; -import { LightSet } from "minimal-polyfills/Set"; -import { MapLike, SetLike, ArrayLike, DateLike } from "./types"; -import { overwriteReadonlyProp } from "../typeSafety/overwriteReadonlyProp"; +import { assert } from "../typeSafety/assert.ts"; +import { Polyfill as Map, LightMap } from "https://raw.github.com/garronej/minimal_polyfills/2.0.1/Map.ts"; +import { LightSet } from "https://raw.github.com/garronej/minimal_polyfills/2.0.1/Set.ts"; +import { MapLike, SetLike, ArrayLike, DateLike } from "./types.ts"; +import { overwriteReadonlyProp } from "../typeSafety/overwriteReadonlyProp.ts"; /** Will work with: * Array diff --git a/src/tools/inDepth/getPrototypeChain.ts b/tools/inDepth/getPrototypeChain.ts similarity index 100% rename from src/tools/inDepth/getPrototypeChain.ts rename to tools/inDepth/getPrototypeChain.ts diff --git a/tools/inDepth/index.ts b/tools/inDepth/index.ts new file mode 100644 index 00000000..b59b755f --- /dev/null +++ b/tools/inDepth/index.ts @@ -0,0 +1,3 @@ + +export * from "./same.ts"; +export * from "./copy.ts"; \ No newline at end of file diff --git a/src/tools/inDepth/same.ts b/tools/inDepth/same.ts similarity index 95% rename from src/tools/inDepth/same.ts rename to tools/inDepth/same.ts index bde9b4b4..a071c9e3 100644 --- a/src/tools/inDepth/same.ts +++ b/tools/inDepth/same.ts @@ -1,7 +1,7 @@ -import { Polyfill as Set } from "minimal-polyfills/Set"; -import { MapLike, SetLike, DateLike, ArrayLike } from "./types"; -import { arrAllEquals } from "../reducers/allEquals"; -import "minimal-polyfills/Object.is"; +import { Polyfill as Set } from "https://raw.github.com/garronej/minimal_polyfills/2.0.1/Set.ts"; +import { MapLike, SetLike, DateLike, ArrayLike } from "./types.ts"; +import { arrAllEquals } from "../reducers/allEquals.ts"; +import "https://raw.github.com/garronej/minimal_polyfills/2.0.1/Object.is.ts"; /** * Function that perform a in depth comparison of two things of arbitrary type T diff --git a/src/tools/inDepth/test.ts b/tools/inDepth/test.ts similarity index 97% rename from src/tools/inDepth/test.ts rename to tools/inDepth/test.ts index f24b8108..7518125d 100644 --- a/src/tools/inDepth/test.ts +++ b/tools/inDepth/test.ts @@ -1,9 +1,9 @@ -import { sameFactory, same } from "./same"; -import { assert } from "../typeSafety/assert"; -import { copy } from "./copy"; -import * as util from "util"; +import { sameFactory, same } from "./same.ts"; +import { assert } from "../typeSafety/assert.ts"; +import { copy } from "./copy.ts"; +import * as util from "https://deno.land/std/node/util.ts"; { diff --git a/src/tools/inDepth/types.ts b/tools/inDepth/types.ts similarity index 92% rename from src/tools/inDepth/types.ts rename to tools/inDepth/types.ts index 4f75b464..b40d2aaf 100644 --- a/src/tools/inDepth/types.ts +++ b/tools/inDepth/types.ts @@ -1,5 +1,5 @@ -import { typeGuard } from "../typeSafety/typeGuard"; -import { getPrototypeChain } from "./getPrototypeChain"; +import { typeGuard } from "../typeSafety/typeGuard.ts"; +import { getPrototypeChain } from "./getPrototypeChain.ts"; type SetLike = { values: () => Iterable; diff --git a/src/tools/isCallableFunction.ts b/tools/isCallableFunction.ts similarity index 100% rename from src/tools/isCallableFunction.ts rename to tools/isCallableFunction.ts diff --git a/src/tools/reducers/allEquals.ts b/tools/reducers/allEquals.ts similarity index 92% rename from src/tools/reducers/allEquals.ts rename to tools/reducers/allEquals.ts index 9971ec37..ae110050 100644 --- a/src/tools/reducers/allEquals.ts +++ b/tools/reducers/allEquals.ts @@ -1,6 +1,6 @@ -import { allEqualsTo } from "./allEqualsTo"; -import { ReduceArguments, toReduceArguments } from "./reduceify"; +import { allEqualsTo } from "./allEqualsTo.ts"; +import { ReduceArguments, toReduceArguments } from "./reduceify.ts"; export function arrAllEquals( arr: readonly ArrOf[], diff --git a/src/tools/reducers/allEqualsTo.ts b/tools/reducers/allEqualsTo.ts similarity index 85% rename from src/tools/reducers/allEqualsTo.ts rename to tools/reducers/allEqualsTo.ts index 0d8718b6..554980ce 100644 --- a/src/tools/reducers/allEqualsTo.ts +++ b/tools/reducers/allEqualsTo.ts @@ -1,6 +1,6 @@ -import { toReduceArguments, ReduceArguments } from "./reduceify"; -import { every } from "./every"; +import { toReduceArguments, ReduceArguments } from "./reduceify.ts"; +import { every } from "./every.ts"; export function arrAllEqualsTo( diff --git a/src/tools/reducers/allUniq.ts b/tools/reducers/allUniq.ts similarity index 79% rename from src/tools/reducers/allUniq.ts rename to tools/reducers/allUniq.ts index d3fb5808..9275318c 100644 --- a/src/tools/reducers/allUniq.ts +++ b/tools/reducers/allUniq.ts @@ -1,6 +1,6 @@ -import { removeDuplicates } from "./removeDuplicates"; -import { allEquals } from "./allEquals"; -import { ReduceArguments, toReduceArguments } from "./reduceify"; +import { removeDuplicates } from "./removeDuplicates.ts"; +import { allEquals } from "./allEquals.ts"; +import { ReduceArguments, toReduceArguments } from "./reduceify.ts"; export function arrAllUniq( arr: readonly ArrOf[], diff --git a/src/tools/reducers/and.ts b/tools/reducers/and.ts similarity index 83% rename from src/tools/reducers/and.ts rename to tools/reducers/and.ts index 99fb2058..870b81aa 100644 --- a/src/tools/reducers/and.ts +++ b/tools/reducers/and.ts @@ -1,4 +1,4 @@ -import { ReduceArguments, toReduceArguments } from "./reduceify"; +import { ReduceArguments, toReduceArguments } from "./reduceify.ts"; export function arrAnd( arr: readonly ArrOf[], diff --git a/src/tools/reducers/contains.ts b/tools/reducers/contains.ts similarity index 85% rename from src/tools/reducers/contains.ts rename to tools/reducers/contains.ts index ab052730..96f554c7 100644 --- a/src/tools/reducers/contains.ts +++ b/tools/reducers/contains.ts @@ -1,5 +1,5 @@ -import { toReduceArguments, ReduceArguments } from "./reduceify"; +import { toReduceArguments, ReduceArguments } from "./reduceify.ts"; export function arrContains( arr: readonly ArrOf[], diff --git a/src/tools/reducers/count.ts b/tools/reducers/count.ts similarity index 84% rename from src/tools/reducers/count.ts rename to tools/reducers/count.ts index ca637df2..f83138be 100644 --- a/src/tools/reducers/count.ts +++ b/tools/reducers/count.ts @@ -1,4 +1,4 @@ -import { toReduceArguments, ReduceArguments } from "./reduceify"; +import { toReduceArguments, ReduceArguments } from "./reduceify.ts"; export function arrCount( arr: readonly ArrOf[], diff --git a/src/tools/reducers/diff.ts b/tools/reducers/diff.ts similarity index 86% rename from src/tools/reducers/diff.ts rename to tools/reducers/diff.ts index 41b4128f..2d0579f3 100644 --- a/src/tools/reducers/diff.ts +++ b/tools/reducers/diff.ts @@ -1,6 +1,6 @@ -import { ReduceArguments, toReduceArguments } from "./reduceify"; -import { contains } from "./contains"; -import { removeDuplicates } from "./removeDuplicates"; +import { ReduceArguments, toReduceArguments } from "./reduceify.ts"; +import { contains } from "./contains.ts"; +import { removeDuplicates } from "./removeDuplicates.ts"; export type ArrDiff = { added: readonly T[]; diff --git a/src/tools/reducers/every.ts b/tools/reducers/every.ts similarity index 84% rename from src/tools/reducers/every.ts rename to tools/reducers/every.ts index 28dd400b..fc8e684e 100644 --- a/src/tools/reducers/every.ts +++ b/tools/reducers/every.ts @@ -1,4 +1,4 @@ -import { ReduceArguments, toReduceArguments } from "./reduceify"; +import { ReduceArguments, toReduceArguments } from "./reduceify.ts"; export function arrEvery( arr: readonly ArrOf[], diff --git a/src/tools/reducers/includes.ts b/tools/reducers/includes.ts similarity index 77% rename from src/tools/reducers/includes.ts rename to tools/reducers/includes.ts index 6ca8266d..4d463bc5 100644 --- a/src/tools/reducers/includes.ts +++ b/tools/reducers/includes.ts @@ -1,5 +1,5 @@ -import { ReduceArguments, toReduceArguments } from "./reduceify"; +import { ReduceArguments, toReduceArguments } from "./reduceify.ts"; export function arrIncludes(arr: readonly ArrOf[], e: ArrOf): boolean { return arr.indexOf(e) >= 0; diff --git a/tools/reducers/index.ts b/tools/reducers/index.ts new file mode 100644 index 00000000..ff7cc805 --- /dev/null +++ b/tools/reducers/index.ts @@ -0,0 +1,28 @@ + +import { allEquals, allEqualsFactory } from "./allEquals.ts"; +import { allEqualsTo, allEqualsToFactory } from "./allEqualsTo.ts"; +import { allUniq, allUniqFactory } from "./allUniq.ts"; +import { and } from "./and.ts"; +import { includes } from "./includes.ts"; +import { count } from "./count.ts"; +import { every } from "./every.ts"; +import { or } from "./or.ts"; +import { removeDuplicates, removeDuplicatesFactory } from "./removeDuplicates.ts"; +import { sameAs, sameAsFactory } from "./sameAs.ts"; +import { partition } from "./partition.ts"; +import { diff } from "./diff.ts"; + +export { + allEquals, allEqualsFactory, + allEqualsTo, allEqualsToFactory, + allUniq, allUniqFactory, + and, + includes, + count, + every, + or, + removeDuplicates, removeDuplicatesFactory, + sameAs, sameAsFactory, + partition, + diff +}; diff --git a/src/tools/reducers/or.ts b/tools/reducers/or.ts similarity index 83% rename from src/tools/reducers/or.ts rename to tools/reducers/or.ts index 373915f0..491fe081 100644 --- a/src/tools/reducers/or.ts +++ b/tools/reducers/or.ts @@ -1,4 +1,4 @@ -import { ReduceArguments, toReduceArguments } from "./reduceify"; +import { ReduceArguments, toReduceArguments } from "./reduceify.ts"; export function arrOr( arr: readonly ArrOf[], diff --git a/src/tools/reducers/partition.ts b/tools/reducers/partition.ts similarity index 92% rename from src/tools/reducers/partition.ts rename to tools/reducers/partition.ts index adf43270..14f572e0 100644 --- a/src/tools/reducers/partition.ts +++ b/tools/reducers/partition.ts @@ -1,7 +1,7 @@ -import { assert, typeGuard } from "../typeSafety"; -import { ReduceArguments, toReduceArguments } from "./reduceify"; +import { assert, typeGuard } from "../typeSafety/index.ts"; +import { ReduceArguments, toReduceArguments } from "./reduceify.ts"; function arrPartitionImpl( arr: readonly ArrOf[], diff --git a/src/tools/reducers/reduceify.ts b/tools/reducers/reduceify.ts similarity index 100% rename from src/tools/reducers/reduceify.ts rename to tools/reducers/reduceify.ts diff --git a/src/tools/reducers/removeDuplicates.ts b/tools/reducers/removeDuplicates.ts similarity index 87% rename from src/tools/reducers/removeDuplicates.ts rename to tools/reducers/removeDuplicates.ts index f3c0ca4e..8fb06e4f 100644 --- a/src/tools/reducers/removeDuplicates.ts +++ b/tools/reducers/removeDuplicates.ts @@ -1,6 +1,6 @@ -import { allEqualsTo } from "./allEqualsTo"; -import { ReduceArguments, toReduceArguments } from "./reduceify"; +import { allEqualsTo } from "./allEqualsTo.ts"; +import { ReduceArguments, toReduceArguments } from "./reduceify.ts"; export function arrRemoveDuplicates( arr: readonly ArrOf[], diff --git a/src/tools/reducers/sameAs.ts b/tools/reducers/sameAs.ts similarity index 94% rename from src/tools/reducers/sameAs.ts rename to tools/reducers/sameAs.ts index 4bd800ee..64bf11a5 100644 --- a/src/tools/reducers/sameAs.ts +++ b/tools/reducers/sameAs.ts @@ -1,5 +1,5 @@ -import { allEquals } from "./allEquals"; -import { ReduceArguments, toReduceArguments } from "./reduceify"; +import { allEquals } from "./allEquals.ts"; +import { ReduceArguments, toReduceArguments } from "./reduceify.ts"; export function arrSameAs( arr: readonly ArrOf[], diff --git a/src/tools/reducers/test.ts b/tools/reducers/test.ts similarity index 96% rename from src/tools/reducers/test.ts rename to tools/reducers/test.ts index 35499d76..6cb7eaec 100644 --- a/src/tools/reducers/test.ts +++ b/tools/reducers/test.ts @@ -1,9 +1,9 @@ -import { assert } from "../typeSafety"; -import { every, allEqualsTo, allEquals, removeDuplicates, partition, allUniq, and, count, includes, or, sameAs, diff } from "./index"; -import { arrEvery } from "./every"; -import { arrPartition } from "./partition"; -import { same } from "../inDepth/same"; +import { assert } from "../typeSafety/index.ts"; +import { every, allEqualsTo, allEquals, removeDuplicates, partition, allUniq, and, count, includes, or, sameAs, diff } from "./index.ts"; +import { arrEvery } from "./every.ts"; +import { arrPartition } from "./partition.ts"; +import { same } from "../inDepth/same.ts"; assert(["foo", "foo", "foo"].reduce(...every(e => e === "foo")) === true); assert(["foo", "foo", "bar"].reduce(...every(e => e === "foo")) === false); diff --git a/src/tools/testing/getPromiseAssertionApi.ts b/tools/testing/getPromiseAssertionApi.ts similarity index 94% rename from src/tools/testing/getPromiseAssertionApi.ts rename to tools/testing/getPromiseAssertionApi.ts index a8b57ccc..c05242e1 100644 --- a/src/tools/testing/getPromiseAssertionApi.ts +++ b/tools/testing/getPromiseAssertionApi.ts @@ -1,6 +1,6 @@ -import { assert } from "../typeSafety"; -import { sameFactory } from "../inDepth/same"; +import { assert } from "../typeSafety/index.ts"; +import { sameFactory } from "../inDepth/same.ts"; export function getPromiseAssertionApi( params?: { takeIntoAccountArraysOrdering: boolean; } diff --git a/tools/testing/index.ts b/tools/testing/index.ts new file mode 100644 index 00000000..1236c671 --- /dev/null +++ b/tools/testing/index.ts @@ -0,0 +1 @@ +export * from "./getPromiseAssertionApi.ts"; \ No newline at end of file diff --git a/src/tools/typeSafety/AsyncReturnType.ts b/tools/typeSafety/AsyncReturnType.ts similarity index 100% rename from src/tools/typeSafety/AsyncReturnType.ts rename to tools/typeSafety/AsyncReturnType.ts diff --git a/src/tools/typeSafety/UnpackPromise.ts b/tools/typeSafety/UnpackPromise.ts similarity index 100% rename from src/tools/typeSafety/UnpackPromise.ts rename to tools/typeSafety/UnpackPromise.ts diff --git a/src/tools/typeSafety/UnpackTypeGuard.ts b/tools/typeSafety/UnpackTypeGuard.ts similarity index 100% rename from src/tools/typeSafety/UnpackTypeGuard.ts rename to tools/typeSafety/UnpackTypeGuard.ts diff --git a/src/tools/typeSafety/assert.ts b/tools/typeSafety/assert.ts similarity index 100% rename from src/tools/typeSafety/assert.ts rename to tools/typeSafety/assert.ts diff --git a/src/tools/typeSafety/defineAccessors.ts b/tools/typeSafety/defineAccessors.ts similarity index 100% rename from src/tools/typeSafety/defineAccessors.ts rename to tools/typeSafety/defineAccessors.ts diff --git a/src/tools/typeSafety/exclude.ts b/tools/typeSafety/exclude.ts similarity index 100% rename from src/tools/typeSafety/exclude.ts rename to tools/typeSafety/exclude.ts diff --git a/src/tools/typeSafety/id.ts b/tools/typeSafety/id.ts similarity index 100% rename from src/tools/typeSafety/id.ts rename to tools/typeSafety/id.ts diff --git a/tools/typeSafety/index.ts b/tools/typeSafety/index.ts new file mode 100644 index 00000000..08c16384 --- /dev/null +++ b/tools/typeSafety/index.ts @@ -0,0 +1,9 @@ +export { assert } from "./assert.ts"; +export { AsyncReturnType } from "./AsyncReturnType.ts"; +export { exclude } from "./exclude.ts"; +export { id } from "./id.ts"; +export { matchVoid } from "./matchVoid.ts"; +export { objectKeys } from "./objectKeys.ts"; +export { typeGuard } from "./typeGuard.ts"; +export { UnpackPromise } from "./UnpackPromise.ts"; +export { UnpackTypeGuard } from "./UnpackTypeGuard.ts"; \ No newline at end of file diff --git a/src/tools/typeSafety/matchVoid.ts b/tools/typeSafety/matchVoid.ts similarity index 100% rename from src/tools/typeSafety/matchVoid.ts rename to tools/typeSafety/matchVoid.ts diff --git a/src/tools/typeSafety/objectKeys.ts b/tools/typeSafety/objectKeys.ts similarity index 100% rename from src/tools/typeSafety/objectKeys.ts rename to tools/typeSafety/objectKeys.ts diff --git a/src/tools/typeSafety/overwriteReadonlyProp.ts b/tools/typeSafety/overwriteReadonlyProp.ts similarity index 100% rename from src/tools/typeSafety/overwriteReadonlyProp.ts rename to tools/typeSafety/overwriteReadonlyProp.ts diff --git a/src/tools/typeSafety/typeGuard.ts b/tools/typeSafety/typeGuard.ts similarity index 100% rename from src/tools/typeSafety/typeGuard.ts rename to tools/typeSafety/typeGuard.ts