Code Monkey home page Code Monkey logo

uce's Introduction

webreflection

WebReflection Ltd

uce's People

Contributors

arthurclemens avatar brettlargent avatar gbishop avatar sethlivingston avatar webreflection avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

uce's Issues

usage with uland

// @ts-ignore
import { Component, render, html, useState } from 'uland'
import { define, svg, css } from 'uce'

const Counter = Component(initialState => {
  const [count, setCount] = useState(initialState)
  return html`
    <button onclick=${() => setCount(count + 1)}>
      Count: ${count}
    </button>
  `
})

customElements.whenDefined('uce-lib').then(() => {
  define('some-widget', {
    init() {
      this.html`
        <div>
          A bounce of counters.
          <hr />
          ${Counter(0)} ${Counter(1)}
        </div>
      `
    },

    render() {
      this.html`
        <div>
          A bounce of counters.
          <hr />
          ${Counter(0)} ${Counter(1)}
        </div>
      `
    },
  })
})

The code above doesn't work, how do I write it correctly? i.e. I want to create a custom element that uses another (virtual) component with hooks, but it is no longer renderable. And why such fragmentation?

double events fired

Hi, I am playing around with uce, I am pretty beginner with custom elements so it could be a stupid question, but I noticed that events "attached" directly via ${this} and automagic on are fired twice.

It is a bug?

Here a replication of the problem:

https://codepen.io/ciaoben/pen/eYgwJWv

(look the console)

SSR Example

the uce - lit-html comparison identifies SSR as a key feature of uce. Is there a SSR example somewhere?

[Question] props - usage with arrays and other non-primitive types, best practice?

I am still just playing around with this, so far liking it very much. As a relatively inexperienced JS developer I just got bitten by the following (it took an hour until it dawned on me what was going on)

Consider the following:

define('my-app', {
    props: {
        foo: 42,
        bar: 23,
        items: []
    },

    // [...]

This worked just fine until I had the glorious idea of putting 2 instances of my-app into my html. The foo and bar properties were independent but the items array was shared between all instances.

I figured out this is because the array will be instantiated once during the call of define() already and then later a reference to it will be shared by all instances.

The only way around I have found is by creating it in the init() method. But should I then assign the array to this.props or only to this? Should i put an empty placeholder with the same name into props?

Or should I use props only for primitive types, because I also noticed it will not detect array manipulation via index or push, etc. and not trigger a render() anyway. My conclusion so far is I should not use props for any non-primitive types and live with that. Is this correct?

uce-template Custom Element slots in plain uce

uce-template provides a helper for initializing custom elements from their initial content named slot:

https://github.com/WebReflection/uce-template/blob/bdf398340dbb9f60309663e131b2c011c2e5ddb4/esm/index.js#L77-L103

const queryHelper = (attr, arr) => element => {
  return [].reduce.call(
    element.querySelectorAll('[' + attr + ']'),
    (slot, node) => {
      let {parentNode} = node;
      do {
        if (parentNode === element) {
          const name = get(node, attr);
          slot[name] = arr ? [].concat(slot[name] || [], node) : node;
          break;
        }
        else if (/-/.test(parentNode.tagName) || get(parentNode, 'is'))
          break;
      } while (parentNode = parentNode.parentNode);
      return slot;
    },
    {}
  );
};


// preloaded imports
const virtualNameSpace = {
  define, render, html, svg, css,
  reactive: stateHandler({useState}),
  ref: queryHelper('ref', false),
  slot: queryHelper('slot', true)
};

Would you recommend replicating this helper for use with plain uce or using another method? (If the former, could slot be added to a future uce release?)

TypeScript support

To use uce with TS, a types definition file would be useful. Would you be willing to add this?

Context support

First, thanks for this fantastic minimalistic Custom Element library!

My question is: are you planning to support a similar functionality to React/Svelte Context, where you set a value on the Context in the parent element and the value is available in child components without explicitly passing it down?
The aim would be to easily integrate uce components with any kind of Redux style store implementation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.