Let's table this object till a later date

Overview

tabling



npm add tabling makes objects lazy

downloads size size

Commit a getter's result for one-time evaluation.

⚙️ Install

npm add tabling

🚀 Usage

import { tabling } from "tabling";

const myObject = tabling({
	get answer() {
		return discover_the_meaning_of_life();
	},
});

myObject.answer; // 42

Where ordinarily, that would look like { answer: discover_the_meaning_of_life() } for a value somebody may never read.

🔎 API

Module: tabling

The main and default module and us Proxy based. Everything is lazy here, the object is built-up over which keys are consumed.

No upfront cost, and slightly slower read time.

Module: tabling/warm

A object based implementation, whereby the result is setup at evaluation time.

Upfront cost, but no read time.

🤔 But which one should I use?

Naturally riddled with assumptions. But If you see the benchmarks below, generally the advice is.

  1. if you've got a long-running process with many reads, the /warm sub-module is what youre after.
    • think like a web-server, where the object is module-scope.
  2. browsers, you're probably after the default (proxy based) api. Very minimal reads, and want fast as possible startup time.

So with that, and by no means bullet-proof answer;

  • server — tabling/warm
  • browser - tabling

💨 Benchmark

via the /bench directory with Node v17.2.0

benchmark :: setup
  default              x 2,442,456 ops/sec ±1.92% (89 runs sampled)
  warm                 x   503,581 ops/sec ±0.69% (93 runs sampled)

benchmark :: jit
  default              x   2,168,685 ops/sec ±1.25% (91 runs sampled)
  warm                 x 430,936 ops/sec ±1.49% (91 runs sampled)

benchmark :: aot
  default              x  27,579,584 ops/sec ±0.52% (89 runs sampled)
  warm                 x 133,821,620 ops/sec ±0.34% (93 runs sampled)

setup — the time to construct the object, without reading from it.

jit — the object is constructed on the hot path, and read from immediately. Think "request bound" objects.

aot — the object is constructed ahead of time, and read later on the hot path. Think "module scope" objects.

❤️ Thanks

Special thanks to @wongmjane for idea!

License

MIT © Marais Rossouw

You might also like...

A Minimalist to do list website where user can add, remove and edit multiple tasks and All the changes user makes in his to do list is saved in browser local storage so that it can be accessed later.

Testing for Add Remove function in To Do List App Jest framework is used for testing. Created (addremove.test.js) for a file containing the add item a

Aug 15, 2022

In this project, I built a simple HTML list of To Do tasks. The list is styled according to the specifications listed later in this lesson. This simple web page is built using webpack and served by a webpack dev server.

Awesome books:JavaScript Using Modules In this project, I built a simple HTML list of To Do tasks. The list is styled according to the specifications

Nov 25, 2022

A Zotero add-on that scans your Markdown reading notes, tags the associated Zotero items, and lets you open notes for the Zotero items in Obsidian.

A Zotero add-on that scans your Markdown reading notes, tags the associated Zotero items, and lets you open notes for the Zotero items in Obsidian.

Zotero Obsidian Citations Adds colored tags to Zotero items that have associated Markdown notes stored in an external folder. Open an associated Markd

Jan 4, 2023

Codism is a Codepen inspired coding playgound that lets you add and modify HTML, CSS and JavaScript

Codism Codism is a Codepen inspired coding playgound that lets you add and modify HTML, CSS and JavaScript to create in order to create cool stuff! Yo

Nov 24, 2022

Lets you add a character to Hacker News links to add social media and OpenGraph previews for sharing on things like Slack or Twitter.

Lets you add a character to Hacker News links to add social media and OpenGraph previews for sharing on things like Slack or Twitter.

news.ycombinator1.com Lets you add a character to Hacker News links to add social media and OpenGraph previews for sharing on things like Slack or Dis

Sep 18, 2022

A type speed checking website which lets you check your typing speed and shows the real-tme leaderboards with mongodb as DB and express as backend

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Mar 27, 2022

zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

Aug 25, 2022

Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Feb 28, 2022

Plugin that lets you create diagrams from textual representation (aka 'Diagrams as Code') within Logseq

Plugin that lets you create diagrams from textual representation (aka 'Diagrams as Code') within Logseq

Logseq - Diagrams as Code Plugin that lets you create diagrams (and other visualizations) from textual representation (aka 'Diagrams as Code') within

Dec 21, 2022
Owner
Marais Rossouw
Marais Rossouw
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Unread-Messages.js is a lightweight library that lets a user add floating number notifications to any object.

Unread-Messages.js About Unread-Messages.js is a lightweight library that lets a user add mobile-like notification counter badge to any object with ju

Mulaza Jacinto 2 Dec 18, 2021
✏️ A small jQuery extension to turn a static HTML table into an editable one. For quickly populating a small table with JSON data, letting the user modify it with validation, and then getting JSON data back out.

jquery-editable-table A small jQuery extension to turn an HTML table editable for fast data entry and validation Demo ?? https://jsfiddle.net/torrobin

Tor 7 Jul 31, 2022
Another table select prompt plugin of inquirer.js, with powerful table render and filters.

inquirer-table-select-prompt Table row selection prompt for Inquirer.js 动机 现有的 inquirer.js 没有支持表格行选中的命令行交互的插件. 社区内能查找到的,只有一个二维数组的 checkbox,eduardobouc

锂电 3 Jan 7, 2023
this is a single-page web application. we built a book website where the user can add , remove and display books. we used modules to implement these functionalities. also, we used the Date class to display the date and time.

Awsome Books In this Project, we have built A Books websites. Built With ?? HTML CSS javascript Git & Github Live Demo Here you can find the live Demo

Nedjwa Bouraiou 10 Aug 3, 2022
This is just a script I put together to check and notify me via email (MailGun) when there's an earlier date before my initial appointment date. It doesn't handle rescheduling.

US-visa-appointment-notifier This is just a script I put together to check and notify me via email (MailGun) when there's an earlier date before my in

Theophilus Omoregbee 13 Jan 4, 2023
Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Vineeth.TR 16 Dec 6, 2022
Omnivore - a complete, open source read-it-later solution for people who like text

Omnivore Omnivore is a complete, open source read-it-later solution for people who like text. We built Omnivore because we love reading and we want it

Omnivore 597 Jan 1, 2023
An open source movie library platform for viewing movie info and saving movies for later.

GoodWatch An open source movie library platform for viewing movie info and saving movies for later. How to get started? Fork and clone the repo. Then

null 13 Apr 28, 2022
Queue is a node.js package to create background jobs in topic-based RabbitMQ exchanges and process them later.

Queue PLG Works Queue helps with managing subscription and publish critical events using RabbitMQ. All events are published through RabbitMQ, using to

PLG Works 23 Sep 21, 2022