observables-with-streams icon indicating copy to clipboard operation
observables-with-streams copied to clipboard

[Experiment] Move package to Deno first

Open lucacasonato opened this issue 3 years ago • 1 comments
trafficstars

As a prelude: I realize this is a very invasive change. If you are not interested, feel free to just close the PR. I mostly did this to get a feel for what our current state of Node->Deno and Deno->NPM tooling is like (I ran out of own packages to convert 🙃).


What?

This PR moves the observables-with-streams package to be written for "Deno first". This means that the TypeScript used is "Deno flavored", i.e. with .ts extensions.

The tests were moved over to Deno.test and https://deno.land/std/testing/asserts.ts. They now run in Deno rather than in a browser. The streams implementation in Deno is just as (or more) correct than Chrome, so the tests are still passing :-). Proof.

How?

  • All code in src/ has had its .ts extensions added in imports
  • In tests/ the Mocha.* calls have been replaced with Deno.test.
  • In tests/ the chai asserts have been replaced with simple assert and assertEquals from std/testing/asserts.ts.
  • src/sources/from-timer.ts has been updated to clear the interval when the stream is closed to appease Deno's test sanitizers. (Fixes #13)
  • CI has been moved to GitHub Actions
  • Formatting has been moved to deno fmt
  • Utility scripts now use make rather than npm run
  • A build.ts script was added that generates a dist/ folder from the source code. It uses dnt to generate the plain JS ESM code and type declaration files. Rollup is then used to generate the dist/dist/really-big-bundle.js.
  • Publishing instructions added to CONTRIBUTING
    1. Bump version in build.ts
    2. make build
    3. cd dist && npm publish
    4. Tag the release in Git (e.g. git tag v1.0.0)
  • Removed a bunch of config files that are now not needed anymore

What's next?

After merging this PR (if you want to), you should register https://deno.land/x/observables-with-streams and create a new release. This will make it easier for Deno users to use the package.

Docs on Netlify can be disabled after this change too, as docs can now be viewed on doc.deno.land. Example: https://doc.deno.land/https://raw.githubusercontent.com/surma/observables-with-streams/28c55be6d855780c677fd1f4ba975f4d3144891d/src/index.ts

lucacasonato avatar Dec 29 '21 20:12 lucacasonato

Just noting that I have a port of this at https://deno.land/x/stream_observables. My fork differs a bit in a couple other ways too e.g. I replaced fromIterable with Deno's readableStreamFromIterable to gain async support.

Anyway, I just want to note how useful observables-with-streams has been for building reactive programs in Deno :) I've used it numerous times over the past year.

For example I just put together a filesystem watch debounce with only a couple lines of code:

    ows.fromIterable(Deno.watchFs(folder))
      .pipeThrough(ows.filter(x => x.kind == 'modify'))
      .pipeThrough(ows.debounce(250))
      .pipeTo(ows.subscribe(reloadFromFs));

danopia avatar Apr 03 '23 12:04 danopia