@blockquote-web-components/blockquote-base-meta

1.4.0 • Public • Published

Lit

BlockquoteBaseMeta is a generic class for sharing information across the DOM tree, inspired by Polymer's iron-meta. It employs the monostate pattern to allow any instance to access the shared information.

The class instances hold the actual data. They must be created before attempting to access them.

BlockquoteBaseMeta uses a Map to store the data. Unlike an Object, a Map allows keys of any type.

Demo

Open in StackBlitz

Usage

import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';

const myDefault = new BlockquoteBaseMeta({
  key: 'basic',
  value: 'foo/bar',
});

console.log(myDefault.byKey('basic')); // foo/bar

Value Getter - String

import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';

const myDefault = new BlockquoteBaseMeta({
  key: 'basic',
  value: 'foo/bar',
});

console.log(myDefault.value); // foo/bar

List Getter - Array

The list getter returns an array of all values stored in the BlockquoteBaseMeta instance.

import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';

const myDefault = new BlockquoteBaseMeta({
  type: 'three',
  key: 'basic',
  value: 'foo/bar',
});

console.log(myDefault.list); // ['foo/bar']

ObjectList Getter - Object

import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';

const myDefault = new BlockquoteBaseMeta({
  type: 'one',
  key: 'basic',
  value: 'foo/bar',
});

console.log(myDefault.objectList); // {basic: 'foo/bar'}

MapList Getter - Map

import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';

const keyInfo = { id: 'dsfaskj0' };
const myDefault = new BlockquoteBaseMeta({
  type: 'two',
  key: keyInfo,
  value: 'foo/bar',
});

console.log(myDefault.mapList); // Map(1) { { id: 'dsfaskj0' } => 'foo/bar' }

src/BlockquoteBaseMeta.js:

class: BlockquoteBaseMeta

Static Fields
Name Privacy Type Default Description Inherited From
types
uuid
Fields
Name Privacy Type Default Description Inherited From
value Sets value to instance type and key
list Returns a list (Array) of the values for that instance `type`
mapList Returns a list (Map) for that instance `type`
objectList Returns a list (Object) for that instance `type`
type type Type of Meta
key key Key for Meta
Methods
Name Privacy Description Parameters Return Inherited From
byKey Returns the value of the provided key for that instance `type` key: * *

Exports

Kind Name Declaration Module Package
js BlockquoteBaseMeta BlockquoteBaseMeta src/BlockquoteBaseMeta.js

src/index.js:

Exports

Kind Name Declaration Module Package
js BlockquoteBaseMeta BlockquoteBaseMeta ./BlockquoteBaseMeta.js

Package Sidebar

Install

npm i @blockquote-web-components/blockquote-base-meta

Weekly Downloads

3

Version

1.4.0

License

MIT

Unpacked Size

15.9 kB

Total Files

5

Last publish

Collaborators

  • oscarmarina