Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
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 many dependent streams.
Usually in a 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 when different streams depend on each other. This utility covers common case and makes creating complicated programs easier.
Let's say, you want to create simple application, that allows you to add two numbers. With pure Cycle.js and cyclejs-stream you can do it like this:
import { applyToDOM, h, Rx } from 'cyclejs';
import createStream from 'cyclejs-stream';
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((interactions) =>
interactions
.get('#a', 'input')
.map(({ target }) => target.value)
);
let changeA$ = createStream((interactions) =>
interactions
.get('#b', 'input')
.map(({ target }) => target.value)
);
applyToDOM('.js-container', (interactions) => {
a$.inject(changeA$);
b$.inject(changeB$);
c$.inject(a$, b$);
vtree$.inject(a$, b$, c$);
interactions.inject(vtree$);
changeA$.inject(interactions);
changeB$.inject(interactions);
return vtree$;
});
Seems easy for now, but when streams number grows, amount of boilerplate will grow proportionally.
With createGroup
you can achieve the same effect in more compact way and create batch of streams from plain functions.
Thanks to inject
method of the group, you can make streams form one group available for streams from another one.
Connection is detected based on names of function parameters and keys of the group object. The whole concept of grouping
streams can help with separation of concerns and increase readability of your code.
import { applyToDOM, h, Rx } from 'cyclejs';
import createGroup from 'cyclejs-group';
let model = createGroup({
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 = createGroup({
changeA$: (interactions) =>
interactions
.get('#a', 'input')
.map(({ target }) => target.value),
changeB$: (interactions) =>
interactions
.get('#b', 'input')
.map(({ target }) => target.value)
});
let view = createGroup({
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'
})
]
)
)
)
});
applyToDOM('.js-container', (interactions) => {
model.inject(intent, model); // self-injection to make a$ and b$ available for c$
view.inject(model);
intent.inject({ interactions });
return view.vtree$;
});
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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.