🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

compostate-element

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compostate-element

compostate + Custom Elements

latest
Source
npmnpm
Version
0.6.0-alpha.1
Version published
Maintainers
1
Created
Source

compostate-element

Web Components bindings for compostate

NPM JavaScript Style Guide

Install

npm install --save compostate compostate-element
yarn add compostate compostate-element
pnpm add compostate compostate-element

Usage

import { ref, effect } from 'compostate';
import { setRenderer, define } from 'compostate-element';
import { render, html } from 'lit-html';

// Setup the element's renderer using Lit
// Any renderer should work
setRenderer((root, result) => {
  render(result, root);
});

// Define an element
define({
  // Name of the element (required)
  name: 'counter-title',
  // Props to be tracked (required)
  props: ['value'],
  // Element setup
  setup(props) {
    // The setup method is run only once
    // it's useful to setup your component logic here.
    effect(() => {
      // Props are reactive
      console.log(`Current count: ${props.value}`);
    });

    // Return the template atom
    // The template's returned value depends
    // on the renderer's templates.
    // For example, you can return a JSX markup
    // if the renderer used is React or Preact.
    return () => (
      html`
        <h1>Count: ${props.value}</h1>
      `
    );
  },
});

define({
  name: 'counter-button',
  setup() {
    const count = ref(0);

    function increment() {
      count.value += 1;
    }

    function decrement() {
      count.value -= 1;
    }

    return () => (
      html`
        <button @click=${increment}>Increment</button>
        <button @click=${decrement}>Decrement</button>
        <counter-title value="${count.value}"></counter-title>
      `
    );
  },
});

License

MIT © lxsmnsyc

Keywords

pridepack

FAQs

Package last updated on 26 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts