Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflow/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ci

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.17.x

- name: Verify formatting
run: make fmt-check

- name: Run tests
run: make test

- name: Test npm build
run: make build
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
node_modules
*.pem
dist
docs
package-lock.json
.vscode
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

7 changes: 7 additions & 0 deletions CONTRIBUTING
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ Contributions made by corporations are covered by a different agreement than
the one above, the
[Software Grant and Corporate Contributor License Agreement]
(https://cla.developers.google.com/about/google-corporate).

### Releasing

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`)
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
# Names should be added to this file as:
# Name <email address>
Surma <[email protected]>
Luca Casonato <[email protected]>
20 changes: 0 additions & 20 deletions Dockerfile

This file was deleted.

38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# Observables with Streams

A library for observables built with [WHATWG streams](https://streams.spec.whatwg.org). This library is inspired by [ReactiveX’s operators](http://reactivex.io/documentation/operators.html) and implements a subset of them using [streams](https://streams.spec.whatwg.org).
A library for observables built with
[WHATWG streams](https://streams.spec.whatwg.org). This library is inspired by
[ReactiveX’s operators](http://reactivex.io/documentation/operators.html) and
implements a subset of them using [streams](https://streams.spec.whatwg.org).

Importing using NPM:

```
npm install --save observables-with-streams
```

The goal of this library is to implement observables making as much use of the platform as possible and being highly tree-shakeable.
Or directlu the browser / Deno:

```js
// JS:
import * as ows from "https://unpkg.com/[email protected]/dist/esm/index.js";

// TS (Deno):
import * as ows from "https://deno.land/x/observables-with-streams/src/index.ts";
```

The goal of this library is to implement observables making as much use of the
platform as possible and being highly tree-shakeable.

## Example

Expand Down Expand Up @@ -45,13 +61,23 @@ The goal of this library is to implement observables making as much use of the p

## Documentation

The (somewhat lacking) documentation for this library is hosted at https://observables-with-streams.surma.technology
You can view docs on:
https://doc.deno.land/https://raw.githubusercontent.com/surma/observables-with-streams/28c55be6d855780c677fd1f4ba975f4d3144891d/src/index.ts

## Caveats

While most browsers have [partial support of streams](https://caniuse.com/#feat=streams) in stable, this library makes heavy use of [TransformStreams](https://streams.spec.whatwg.org/#ts-model), which are currently not well supported. Until browsers catch up, I can recommend [Mattias Buelens'](https://twitter.com/MattiasBuelens) [web-streams-polyfill](https://npm.im/web-streams-polyfill).

For a good primer about streams, read this [blog post](https://jakearchibald.com/2016/streams-ftw/) by [Jake Archibald](https://twitter.com/jaffathecake/) (he is aware the title hasn’t aged well).
While most browsers have
[partial support of streams](https://caniuse.com/#feat=streams) in stable, this
library makes heavy use of
[TransformStreams](https://streams.spec.whatwg.org/#ts-model), which are
currently not well supported. Until browsers catch up, I can recommend
[Mattias Buelens'](https://twitter.com/MattiasBuelens)
[web-streams-polyfill](https://npm.im/web-streams-polyfill).

For a good primer about streams, read this
[blog post](https://jakearchibald.com/2016/streams-ftw/) by
[Jake Archibald](https://twitter.com/jaffathecake/) (he is aware the title
hasn’t aged well).

---

Expand Down
47 changes: 47 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { build } from "https://deno.land/x/[email protected]/mod.ts";
import { rollup } from "https://esm.sh/[email protected]";
import { minify } from "https://esm.sh/[email protected]";

await build({
entryPoints: ["./src/index.ts"],
outDir: "./dist",
testPattern: "./tests/**/*.ts",
cjs: false,
shims: {
deno: "dev",
},
package: {
// package.json properties
name: "observables-with-streams",
version: "0.6.1",
description: "A library of observables built with streams",
author: "Surma <[email protected]>",
license: "Apache-2.0",
},
});

// post build steps
Deno.copyFileSync("LICENSE", "dist/LICENSE");
Deno.copyFileSync("README.md", "dist/README.md");

// Generate dist/dist/really-big-bundle.js
const res = await rollup({
input: "dist/esm/index.js",
plugins: [
{
name: "terser",
async renderChunk(code) {
const result = await minify(code, { compress: true, mangle: true });
return {
code: result.code!,
map: result.map,
};
},
},
],
});
await res.write({
file: "dist/dist/really-big-bundle.js",
format: "umd",
name: "ows",
});
73 changes: 0 additions & 73 deletions karma.conf.cjs

This file was deleted.

11 changes: 11 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fmt:
deno fmt ./{src,tests}/**/*.ts *.{md,json,js}

fmt-check:
deno fmt --check ./{src,tests}/**/*.ts *.{md,json,js}

build:
deno run --allow-read --allow-write --allow-run --allow-env --unstable build.ts

test:
deno test --unstable tests/**/*.ts
39 changes: 0 additions & 39 deletions package.json

This file was deleted.

3 changes: 0 additions & 3 deletions renovate.json

This file was deleted.

16 changes: 0 additions & 16 deletions rollup.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/combiners/amb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* limitations under the License.
*/

import { Observable } from "../types.js";
import { Observable } from "../types.ts";

/**
* Takes in multiple observables but only emits items from the first observable
Expand All @@ -25,7 +25,7 @@ export function amb<T>(...os: Array<Observable<T>>): Observable<T> {
return new ReadableStream(
{
async start(controller) {
const readers = os.map(o => o.getReader());
const readers = os.map((o) => o.getReader());
const reads = readers.map(async (r, i) => [await r.read(), i] as const);
let [{ value, done }, i] = await Promise.race(reads);
reads
Expand All @@ -42,8 +42,8 @@ export function amb<T>(...os: Array<Observable<T>>): Observable<T> {
controller.enqueue(value!);
({ value, done } = await fastestObs.read());
}
}
},
},
{ highWaterMark: 0 }
{ highWaterMark: 0 },
);
}
Loading