Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { updateLogger } = require('./updateLogger.js');
const { batch, defer, none } = ferp.effects;
const readFile = (file, errorMessage, successMessage) => defer(new Promise((done) => {
fs.readFile(file, { encoding: 'utf-8' }, (err, data) => {
if (err) {
done({ type: errorMessage, file, err });
} else {
done({ type: successMessage, file, data });
}
});
}));
ferp.app({
init: [
null,
batch([
readFile(path.resolve(__dirname, './hello-world.txt'), 'READ_ERR', 'READ_OK'),
readFile(path.resolve(__dirname, './hello-world.txt.garbage'), 'READ_ERR', 'READ_OK'),
]),
],
update: updateLogger((message, state) => {
switch (message.type) {
case 'READ_OK':
// Can do something with message.data
return [state, none()];
case 'READ_ERR':
// Can do something with message.err
const main = () => ferp.app({
init: [
{
todo: [],
},
batch([4, 2, 5, 3, 1, 7, 6].map(number => (
fetchTodoItem(number, { type: 'ADD_TODO' })
))),
],
update: updateLogger(update),
});
const createApp = () => ferp.app({
init: () => [
initialState,
batch([
{ type: 'ADD_PLAYER', playerId: Math.random().toString(36).substr(7) },
{ type: 'ADD_PLAYER', playerId: Math.random().toString(36).substr(7) },
{ type: 'ADD_PLAYER', playerId: Math.random().toString(36).substr(7) },
{ type: 'ADD_PLAYER', playerId: Math.random().toString(36).substr(7) },
{ type: 'TICK' },
]),
],
update: (message, state) => {
const result = appReducer(view)(message, state);
switch (message.type) {
case 'KEY_DOWN':
return withMoreEffects(result)([
effectForKeyEvent(true, message.key, state.players),
const main = () => ferp.app({
init: [
0,
delay(null, 1000),
],
update: updateLogger(update),
});
const ferp = require('ferp');
const { updateLogger } = require('./updateLogger.js');
const { every } = ferp.subscriptions;
const { none } = ferp.effects;
ferp.app({
init: [
0,
none(),
],
update: updateLogger((_, state) => {
const nextState = state + 1;
return [
nextState,
none(),
];
}),
subscribe: state => [
state < 5 && [every, 'INCREMENT', 1000],
],
const main = () => ferp.app({
init: [{ logs: [] }, none()],
update: router({
'GET /': showState,
'GET /not-found': fourOhFour,
}),
subscribe: () => [
[serverSubscription, http.createServer, 8080, 'ROUTE'],
],
});
const main = () => ferp.app({
init: [
initialState,
superfineEffect(render, initialState, { type: 'UPDATE_NODE' }),
],
update,
});