Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.41 KB

README.md

File metadata and controls

53 lines (41 loc) · 1.41 KB

Overview

Installation

npm i --save @frecency/core
npm i --save @frecency/indexeddb-datasource # if you need persistence

Usage

import createVisit from "@frecency/core";

const halflife = 7 * 24 * 60 * 60 * 1000; // 7 days
const visit = createVisit(halflife);

const visita = visit();
const visitb = visit(visita);
// ...
//
// Very often you are not going to want keep the scores in memory, you may want
// to persist them so that they can be recalled later between pages, app
// launches, etc.
//
// For those working in the browser, we provide a datasource that can persist
// and recall scores from IndexedDB.
//

import { initDB } from "@frecency/indexeddb-datasource";

const datasource = initDB("unique-identitier-used-as-name-of-database");

await datasource.visit("namespace.selector", "contoso");
await datasource.visit("namespace.selector", "contoso");
await datasource.visit("namespace.selector", "acme");
await datasource.visit("namespace.selector", "contoso");
await datasource.visit("namespace.selector", "acme");
await datasource.visit("namespace.selector", "contoso");
await datasource.visit("namespace.selector", "contoso");
await datasource.visit("namespace.selector", "contoso");

// Results are returned ordered by their score
const list = await datasource.list("namespace.selector");
console.table({ list });