pancetta
v0.1.0
Published
A lightweight FRP framework based on Bacon.js
Downloads
1
Readme
Pancetta
A lightweight FRP library based on Bacon.js
Usage
var input = Pancetta.fromEvent($('#new-message'), 'keydown')
input.filter(function(event) {
return event.which === 13;
}).map(function(event) {
return event.target.value;
}).flatMap(function(message) {
return Pancetta.fromPromise($.post('/restAPI', message));
}).scan(function(messages, newMessage) {
return messages.concat([newMessage]);
}, []).map(Handlebars.compile(
'{{#each this}}<li>{{this}}</li>{{/each}}'
)).subscribe(function(markup) {
$('#messages').html(markup);
});
var submits = Pancetta.fromEvent($('#my-form'), 'submit').do(function(event) {
event.preventDefault();
}).map(function(event) {
return $(event.target).serialize();
}).flatMap(function(data) {
return Pancetta.fromPromise($.post('/new-submission', data));
}).scan(function(submissions, submission) {
return submissions.concat([submission]);
}, []);
submits.subscribe(function(submissions) {
React.renderComponent(SubsView({submissions: submissions}), $('#subs'));
});