How to use the @graffy/common.page function in @graffy/common

To help you get started, we’ve selected a few @graffy/common 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 usegraffy / graffy / example / mockVisitorList.js View on Github external
import faker from 'faker';
import {
  graph,
  link,
  page,
  merge,
  unwrap,
  makeStream,
  setVersion,
} from '@graffy/common';

// import { debug } from '@graffy/testing';

const TARGET = 2000;

const state = graph({ visitors: {}, visitorsByTime: page({}) });
const freeIds = new Set();
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

const listeners = new Set();

export default function(g) {
  g.onGet(() => {
    // console.log('Get: Returning', debug(state));
    ts = Date.now();
    setVersion(state, ts);
    return state;
  });

  g.onSub(() =>
    makeStream((push, _end) => {
      listeners.add(push);
github usegraffy / graffy / example / mockVisitorList.js View on Github external
function visitorInfo() {
  return {
    name: faker.internet.userName(),
    avatar: faker.internet.avatar(),
    pageviews: page({
      [ts]: faker.internet.url(),
    }),
  };
}
github usegraffy / graffy / src / website / components / Demo / Source.js View on Github external
function finalize(value) {
  if (!value || typeof value !== 'object') return value;
  const obj = {};
  if (Array.isArray(value)) {
    value.forEach((v, i) => (obj[encodeKey(i)] = finalize(v)));
    return page(obj);
  }
  for (const i in value) obj[i] = finalize(value[i]);
  return obj;
}