How to use the ferp.app function in ferp

To help you get started, we’ve selected a few ferp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ferp-js / ferp / examples / cli / file-reader-node.js View on Github external
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
github ferp-js / ferp / examples / cli / xhr-request / main.js View on Github external
const main = () => ferp.app({
  init: [
    {
      todo: [],
    },
    batch([4, 2, 5, 3, 1, 7, 6].map(number => (
      fetchTodoItem(number, { type: 'ADD_TODO' })
    ))),
  ],

  update: updateLogger(update),
});
github ferp-js / ferp / examples / game-input / main.js View on Github external
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),
github ferp-js / ferp / examples / cli / timer-with-effects / main.js View on Github external
const main = () => ferp.app({
  init: [
    0,
    delay(null, 1000),
  ],

  update: updateLogger(update),
});
github ferp-js / ferp / examples / cli / timer-with-subscription.js View on Github external
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],
  ],
github ferp-js / ferp / examples / http-server / src / main.js View on Github external
const main = () => ferp.app({
  init: [{ logs: [] }, none()],

  update: router({
    'GET /': showState,
    'GET /not-found': fourOhFour,
  }),

  subscribe: () => [
    [serverSubscription, http.createServer, 8080, 'ROUTE'],
  ],
});
github ferp-js / ferp / examples / with-superfine / src / main.js View on Github external
const main = () => ferp.app({
  init: [
    initialState,
    superfineEffect(render, initialState, { type: 'UPDATE_NODE' }),
  ],

  update,
});

ferp

Build functional and pure applications in NodeJS and the Browser!

MIT
Latest version published 2 years ago

Package Health Score

42 / 100
Full package analysis