Skate A functional reactive abstract package

Skate A functional reactive abstract package

2022-11-10 0 774
Resource Number 47837 Last Updated 2025-02-21
¥ 0HKD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

The Skate recommended in this issue is a functional reactive abstract Web component standard as a set of packages that allow you to write small, fast, and scalable Web components using popular video libraries such as React, Preact, and LitHTML.

Skate A functional reactive abstract package插图

Skate feature

  • Compatible components across frameworks.
  • Render components with your favorite gallery, or not at all.
  • Guidelines for best practices when reflecting between attributes, attributes, and events, and when reacting to attributes, attributes, and events.
  • Full TypeScript support.

Skate

The easiest way to get up and running is to start with a pre-configured element, such as @skatejs/element-lit-html.

npm i  @skatejs/element-lit-html

Simple example

import Element, { html } from '@skatejs/element-lit-html';

export default class extends Element {
  static get props() {
    return {
      name: String
    };
  }
  render() {
    return html`
      Hello, ${this.name}!
    `;
  }
}

cli

There is a CLI to help you get up and running:
https://skatejs.netlify.com/packages/cli.

$ npm i -g @skatejs / cli
$skatejs

filler

Skate builds on custom elements and shadow DOM standards. It is able to run without the Shadow DOM – it just means that you are not wrapping any of the HTML or styles of your components. This also means that you can provide a way to project content (i.e. < slot>) . It is highly recommended that you use the Shadow DOM whenever possible.

Although most modern browsers support these standards, some still require polyfill to implement missing or inconsistent behavior for them.

< Browser support

Skate supports all Evergreens and IE11 and is constrained by polyfills’ browser support matrix.

webcomponents.js (v1 polyfills)

A set of polyfill supporting Web component specifications:

  • Custom Elements v1 : Allows authors to define their own custom tags (spec, tutorial, polyfill).
  • Shadow DOM v1 : Encapsulation is provided by hiding DOM subtrees under shadow roots (spec, tutorial, shadydom polyfill, shadycss polyfill).

Includes some small polyfill for browsers that need it:

  • HTMLTemplateElement
  • Promise
  • Event, CustomEvent,MouseEvent constructor and Object.assign, Array.from (see webcomponents-platform)
  • URL constructor

How to use

< Install polyfill

npm install  @webcomponents/webcomponentsjs

You can also load code from the CDN, such as unpkg: https ://unpkg.com/@
webcomponents/webcomponentsjs@^2/

Using webcomponents-bundle.js

Contains all
The webcomponents-bundle.jsweb component polyfills with any supported browser. All polyfill codes will be loaded, but each polyfill is only used for feature-based detection. The bundle includes custom elements, Shady DOM/CSS, and common platform polyfills (such as ES6 Promises, constructible events, etc.) (required by Internet Explorer 11) and templates (required by IE 11 and Edge).

Using webcomponents-bundle.js is very simple, but it loads code that most modern browsers don’t need, slowing down page loads. For best performance, use webcomponents-loader.js.

Here’s an example:

<!-- load webcomponents bundle, which includes all the necessary polyfills -->
<script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>

<!-- load the element -->
<script type="module" src="my-element.js"></script>

< ! -- use the element --> 
< my-element> < /my-element> 

Use webcomponents-loader.js

This webcomponents-loader.js is a client loader that uses feature detection to dynamically load the smallest polyfill package.

webcomponents-loader.js can load synchronously or asynchronously according to your needs.

Inline

< p data – track = “48” > if you have an inline source webcomponent – loader. Js, then you should be specified window. The WebComponents. Root as the root of loading polyfill. For example:

< script> 
window.WebComponents = window.WebComponents || {};
window.WebComponents.root = 'node_modules/@webcomponents/webcomponentsjs/';
< /script> 

This property is used to build the URL of the selected bundle, so you should only set it to a value that is not affected by user control data. If the trusted type is enforced, this attribute should be TrustedScriptURL.

< Synchronization

When loading synchronously, webcomponents-loader.js behaves like webcomponents-bundle.js.

loads the appropriate package document.write() to ensure that WebComponent polyfill is available for subsequent scripts and modules.

Here’s an example:

<!-- load the webcomponents loader, which injects the necessary polyfill bundle -->
<script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>

<!-- load the element -->
<script type="module" src="my-element.js"></script>

< ! -- use the element --> 
< my-element> < /my-element> 

Asynchronous

When loaded asynchronously with the defer attribute, the polyfill package will be loaded asynchronously, This means that scripts and modules that depend on the webcomponents API must load using the webcomponents.waitfor function.

The WebComponents.waitFor function takes the callback function as an argument and evaluates the callback after loading the polyfill package.

The

callback function should load scripts that polyfills (typically via import(‘my-script.js’)) and should return a promise that parses after all scripts have been loaded.

Here’s an example:

< ! -- Load polyfills;  note that "loader" will load these async --> 
< script
src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"
defer
> < /script> 

< ! -- Load a custom element definitions in `waitFor` and return a promise --> 
< script type="module"> 
WebComponents.waitFor(() =>  {
// At this point we are guaranteed that all required polyfills have
// loaded, and can use web components API's.
// The standard pattern is to load element definitions that call
// `customElements.define` here.
// Note: returning the import's promise causes the custom elements
// polyfill to wait until all definitions are loaded and then upgrade
// the document in one batch, for better performance.
return import('my-element.js');
});
< /script> 

< ! -- Use the custom element --> 
< my-element> < /my-element> 

—END—

Open Source license: MIT license

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free Source Code Skate A functional reactive abstract package https://ictcoder.com/skate-a-functional-reactive-abstract-package/

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. ICTcoder will then settle the payment for the seller. Note: Please ensure to place your order and make payment through ICTcoder. If you do not place your order and make payment through ICTcoder, and the seller sends fake source code or encounters any issues, ICTcoder will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by ICTcoder until 7 days after the transaction is completed and both parties confirm that there are no issues. ICTcoder will then settle with the seller. In case of any disputes, ICTcoder will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through ICTcoder, any issues and disputes have nothing to do with ICTcoder, and ICTcoder will not be responsible for any liabilities!
View details
  • 1. ICTcoder will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. ICTcoder cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact ICTcoder for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that ICTcoder can intervene quickly.
View details
  • 1. As a third-party intermediary platform, ICTcoder solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the ICTcoder platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

ICTcoder Customer Service

24-hour online professional services