Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
cyclejs-group
Advanced tools
Utility for CycleJS framework for reducing boilerplate when creating groups of streams
Utility for the Cycle.js framework for reducing boilerplate when creating groups of streams.
Usually ina Cycle.js application or component you want to create more than one stream, especially for intent and model parts. It's 100% possible to do it with pure JS, but it requires a lot of boilerplate code. This utility covers common case and lets creating complicated programs easily.
Let's say, you want to create simple application, that allows you to add two numbers. With pure JS and Cycle.js you can do it like this:
import { createStream, render, h, Rx } from 'cyclejs';
let a$ = createStream((changeA$) => changeA$
.map(value => parseInt(value, 10))
.filter(value => !isNaN(value))
.startWith(1)
.distinctUntilChanged()
);
let b$ = createStream((changeB$) => changeB$
.map(value => parseInt(value, 10))
.filter(value => !isNaN(value))
.startWith(1)
.distinctUntilChanged()
);
let c = createStream((a$, b$) => Rx.Observable.combineLatest(
a$,
b$,
(a, b) => a + b
));
let vtree$ = createStream((a$, b$, c$) =>
Rx.Observable.combineLatest(a$, b$, c$, (a, b, c) =>
h('form',
h('fieldset', [
h('legend', 'Add two numbers'),
h('input#a', {
type: 'number',
value: a,
}),
h('input#b', {
type: 'number',
value: b,
}),
h('output', {
value: c,
htmlFor: 'a,b'
})
])
)
)
);
let changeA$ = createStream((interaction$) =>
interaction$
.choose('#a', 'input')
.map(({ target }) => target.value)
);
let changeA$ = createStream((interaction$) =>
interaction$
.choose('#b', 'input')
.map(({ target }) => target.value)
);
let interaction$ = createStream((vtree$) => render(vtree$, document.body).interaction$);
a$.inject(changeA$);
b$.inject(changeB$);
c$.inject(a$, b$);
vtree$.inject(a$, b$, c$);
interaction$.inject(vtree$);
changeA$.inject(interaction$);
changeB$.inject(interaction$);
Seems easy for now, but when streams number grows, amount of boilerplate will grow proportionally. With createStreamsGroup
you can achieve the same effect in more compact way and create batch of streams from plain functions. Each stream in the group will be injected input streams given by the inject
method of the group, where this connection is detected based on names of function parameters and keys of the group object.
import { createStream, render, h, Rx } from 'cyclejs';
import createStreamsGroup from 'cyclejs-create-streams-group';
let model = createStreamsGroup({
a$: (changeA$) => changeA$
.map(value => parseInt(value, 10))
.filter(value => !isNaN(value))
.startWith(1)
.distinctUntilChanged()
b$: (changeB$) => changeB$
.map(value => parseInt(value, 10))
.filter(value => !isNaN(value))
.startWith(1)
.distinctUntilChanged(),
c$: (a$, b$) => Rx.Observable.combineLatest(
a$,
b$,
(a, b) => a + b
)
});
let intent = createStreamsGroup({
changeA$: (interaction$) => interaction$
.choose('#a', 'input')
.map(({ target }) => target.value),
changeB$: (interaction$) => interaction$
.choose('#b', 'input')
.map(({ target }) => target.value)
});
let view = createStreamsGroup({
vtree$: (a$, b$, c$) => Rx.Observable.combineLatest(
a$, b$, c$,
(a, b, c) =>
h('form',
h('fieldset', [
h('legend', 'Add two numbers'),
h('input#a', {
type: 'number',
value: a,
}),
h('input#b', {
type: 'number',
value: b,
}),
h('output', {
value: c,
htmlFor: 'a,b'
})
])
)
)
});
let user = createStreamsGroup({
interaction$: (vtree$) => render(vtree$, document.body).interaction$
});
model.inject(intent);
view.inject(model);
user.inject(view);
intent.inject(user);
FAQs
Utility for CycleJS framework for reducing boilerplate when creating groups of streams
The npm package cyclejs-group receives a total of 14 weekly downloads. As such, cyclejs-group popularity was classified as not popular.
We found that cyclejs-group demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.