How to use apprun - 10 common examples

To help you get started, we’ve selected a few apprun 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 yysun / apprun-hn / src / api.ts View on Github external
const ref = db.child(path);
  return new Promise((resolve) => {
    ref.once('value', snapshot => resolve(snapshot.val())); // tslint:disable-line
  })
}

const fetchItem = async (id): Promise => {
  const item = await fetch(`item/${id}`);
  if (item && item.kids) item.kids = await Promise.all(item.kids.map(async kid => {
    return typeof kid === 'number' ?
      await fetchItem(kid) : kid
  }));
  return item;
}

app.on('get-list', async (type, list) => {
  const fetchListItems = async ({ items, min, max }) => {
    await Promise.all(items.map(async (id, idx) => {
      if (idx >= min && idx < max && (typeof id === 'number')) {
        items[idx] = await fetch(`item/${id}`)
      }
    }));
    app.run('render');
  }
  if (list.items.length) {
    await fetchListItems(list);
  } else {
    const ref = db.child(`${type}stories`);
    ref.on('value', async snapshot => {
      list.items = snapshot.val();
      await fetchListItems(list);
    });
github yysun / apprun-hn / src / api.ts View on Github external
}
    }));
    app.run('render');
  }
  if (list.items.length) {
    await fetchListItems(list);
  } else {
    const ref = db.child(`${type}stories`);
    ref.on('value', async snapshot => {
      list.items = snapshot.val();
      await fetchListItems(list);
    });
  }
});

app.on('get-item', (id, state) => {
  if (!id) return;
  const ref = db.child(`item/${id}`);
  ref.on('value', async snapshot => {
    state[id] = snapshot.val();
    if (state[id].kids) {
      state[id].kids = await Promise.all(state[id].kids.map(async kid => {
        return typeof kid === 'number' ?
          await fetchItem(kid) : kid
      }));
    }
    app.run('render');
  });
});
github krausest / js-framework-benchmark / frameworks / non-keyed / apprun / src / main.tsx View on Github external
component.run(t.id);
        stopMeasure();
    } else if (t.matches('.remove')) {
        e.preventDefault();
        startMeasure('remove');
        component.run('remove', getId(t));
        stopMeasure();
    } else if (t.matches('.lbl')) {
        e.preventDefault();
        startMeasure('select');
        component.run('select', getId(t));
        stopMeasure();
    }
});

app.on('//', _ => { })
app.on('#', _ => { })

let component = new Component(store, view, update);
component.start(document.getElementById('main'));
github krausest / js-framework-benchmark / frameworks / non-keyed / apprun / src / main.tsx View on Github external
stopMeasure();
    } else if (t.matches('.remove')) {
        e.preventDefault();
        startMeasure('remove');
        component.run('remove', getId(t));
        stopMeasure();
    } else if (t.matches('.lbl')) {
        e.preventDefault();
        startMeasure('select');
        component.run('select', getId(t));
        stopMeasure();
    }
});

app.on('//', _ => { })
app.on('#', _ => { })

let component = new Component(store, view, update);
component.start(document.getElementById('main'));
github krausest / js-framework-benchmark / apprun-v1.8.3-keyed / src / main.tsx View on Github external
component.run(t.id);
        stopMeasure();
    } else if (t.matches('.remove')) {
        e.preventDefault();
        startMeasure('remove');
        component.run('remove', getId(t));
        stopMeasure();
    } else if (t.matches('.lbl')) {
        e.preventDefault();
        startMeasure('select');
        component.run('select', getId(t));
        stopMeasure();
    }
});

app.on('//', _ => { })
app.on('#', _ => { })

let component = new Component(store, view, update);
component.start(document.getElementById('main'));
github krausest / js-framework-benchmark / apprun-v1.8.3-keyed / src / main.tsx View on Github external
stopMeasure();
    } else if (t.matches('.remove')) {
        e.preventDefault();
        startMeasure('remove');
        component.run('remove', getId(t));
        stopMeasure();
    } else if (t.matches('.lbl')) {
        e.preventDefault();
        startMeasure('select');
        component.run('select', getId(t));
        stopMeasure();
    }
});

app.on('//', _ => { })
app.on('#', _ => { })

let component = new Component(store, view, update);
component.start(document.getElementById('main'));
github yysun / apprun-hn / src / hacker-news.tsx View on Github external
'#': (state, type, id) => {
    type = type || 'top';
    state.type = type;
    state[type] = state[type] || { min: 0, max: page_size, items: [] };
    state.id = id;
    if (type === 'item')
      app.run('get-item', id, state);
    else
      app.run('get-list', type, state[type]);
  },
  'render': state => state,
github yysun / apprun-hn / src / api.ts View on Github external
const fetchListItems = async ({ items, min, max }) => {
    await Promise.all(items.map(async (id, idx) => {
      if (idx >= min && idx < max && (typeof id === 'number')) {
        items[idx] = await fetch(`item/${id}`)
      }
    }));
    app.run('render');
  }
  if (list.items.length) {
github yysun / apprun-hn / src / hacker-news.tsx View on Github external
'#': (state, type, id) => {
    type = type || 'top';
    state.type = type;
    state[type] = state[type] || { min: 0, max: page_size, items: [] };
    state.id = id;
    if (type === 'item')
      app.run('get-item', id, state);
    else
      app.run('get-list', type, state[type]);
  },
  'render': state => state,
github yysun / apprun-hn / src / hacker-news.tsx View on Github external
'more': state => {
    const list = state[state.type];
    list.max = Math.min(list.max + page_size, list.items.length)
    app.run('get-list', state.type, list);
  },
}

apprun

JavaScript library that has Elm inspired architecture, event pub-sub and components

MIT
Latest version published 2 months ago

Package Health Score

66 / 100
Full package analysis