JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 34
  • Score
    100M100P100Q51948F
  • License MIT

Package Exports

  • be-it
  • be-it/be-link-valued.js

Readme

be-it

be-it is a vaguely named custom enhancement for DOM elements, whose mission is rather obscure but quite important. It allows deriving and forwarding microdata settings / values from meta and link tags to and from properties of other DOM (custom) elements. "it" stands for "itemized and transformed", if that helps remember the name.

This allows applications to hydrate without having to pass and parse data separately, and provide search engines with accurate information.

Playwright Tests NPM version How big is this package in your project?

It works well with other custom enhancements, including be-sharing and be-linked:

<div itemscope 
    be-scoped='{
        "count": 30,
        "description": "Mr. Banks flying a kite with his kids.",
        "isHappy": true
    }'
    be-sharing='
        Share * from scope.
    '
>
    <link itemprop=isHappy be-it=disabled>
    <meta itemprop=count be-it=maxLength>
    <input>
    <meta itemprop=description be-it=alt>
    <img>
</div>

be-it also supports hydrating the value in the opposite direction from server rendered HTML:

<link be-it=disabled>
<meta itemtype="https://schema.org/Number" be-it=maxLength>
<input disabled maxlength=37>

...updates the microdata so it matches the initial values of the input element.

Deriving initial value from SSR [TODO]

<link itemprop=isHappy be-it=checked🌩️>

Two-way binding

be-it supports a two way binding option if the name of the property to share ends with a 🔃 character. (On windows, type flying windows button, then the period, and search for clockwise vertical arrow.)

<link itemprop=isHappy be-it=checked🔃>
<input type=checkbox>

This will cause the checkbox to notify the source's isHappy property of the change.

Conditionally displaying a template element

<link itemprop=isHappy be-it=content-display>
<template>
    <my-content></my-content>
</template>

Transforming peer elements [TODO]

be-it can also disseminate its value to other peer elements within the Shadow DOM realm, using DTR syntax:

<span><span>
<link itemprop=isHappy be-it='{
    "prop": "checked",
    "twoWay": true,
    "transform": {
        "span": "."
    }
}'>
<input type=checkbox>

If different values should be passed based on whether the value of itemprop is truthy or falsy, use the transformIfTruty, transformIfFalsy properties.

Viewing Your Element Locally

  1. Install git.
  2. Fork/clone this repo.
  3. Install node.h
  4. Open command window to folder where you cloned this repo.
  5. npm install

  6. npm run serve

  7. Open http://localhost:3030/demo/ in a modern browser.

Running Tests

> npm run test