Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cyclejs-group

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cyclejs-group - npm Package Compare versions

Comparing version 0.3.6 to 0.3.7

dist/create-group.js

8

package.json
{
"name": "cyclejs-group",
"version": "0.3.6",
"version": "0.3.7",
"author": "Eryk Napierala",

@@ -18,3 +18,3 @@ "description": "Utility for CycleJS framework for reducing boilerplate when creating groups of streams",

],
"main": "dist/create-streams-group.js",
"main": "dist/create-group.js",
"dependencies": {

@@ -49,4 +49,4 @@ "core-js": "^0.9.6",

"test": "npm run jshint && npm run mocha",
"browserify": "browserify src/create-streams-group.js -t babelify --standalone createStreamsGroup --outfile dist/cyclejs-group.js",
"uglify": "uglifyjs dist/cycle.js -o dist/cycle.min.js",
"browserify": "browserify src/create-group.js -t babelify --standalone createGroup --outfile dist/cyclejs-group.js",
"uglify": "uglifyjs dist/cyclejs-group.js -o dist/cyclejs-group.min.js",
"dist": "npm run browserify && npm run uglify",

@@ -53,0 +53,0 @@ "precompile": "rm -rf dist/ && mkdir -p dist",

@@ -5,7 +5,7 @@ # cyclejs-group

## Why may I need it?
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.
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. This utility covers common case and makes creating complicated programs easier.
## Example usage
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:
Let's say, you want to create simple application, that allows you to add two numbers. With pure Cycle.js you can do it like this:

@@ -16,53 +16,52 @@ ```javascript

let a$ = createStream((changeA$) => changeA$
.map(value => parseInt(value, 10))
.filter(value => !isNaN(value))
.startWith(1)
.distinctUntilChanged()
.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()
.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
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'
})
])
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)
interaction$
.choose('#a', 'input')
.map(({ target }) => target.value)
);
let changeA$ = createStream((interaction$) =>
interaction$
.choose('#b', 'input')
.map(({ target }) => target.value)
interaction$
.choose('#b', 'input')
.map(({ target }) => target.value)
);

@@ -81,64 +80,64 @@

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.
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.
```javascript
import { createStream, render, h, Rx } from 'cyclejs';
import createStreamsGroup from 'cyclejs-create-streams-group';
import createGroup from 'cyclejs-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 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 = createStreamsGroup({
changeA$: (interaction$) => interaction$
.choose('#a', 'input')
.map(({ target }) => target.value),
changeB$: (interaction$) => interaction$
.choose('#b', 'input')
.map(({ target }) => target.value)
let intent = createGroup({
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 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'
})
]
)
)
)
)
});
let user = createStreamsGroup({
interaction$: (vtree$) => render(vtree$, document.body).interaction$
let user = createGroup({
interaction$: (vtree$) => render(vtree$, document.body).interaction$
});
model.inject(intent);
model.inject(intent, model); // self-injection to make a$ and b$ available for c$
view.inject(model);

@@ -145,0 +144,0 @@ user.inject(view);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc