Giter VIP home page Giter VIP logo

element-behaviors's Introduction

LUME

A toolkit that simplifies the creation of rich and interactive 2D or 3D experiences.

Home  ·  Documentation  ·  Examples  ·  Forum  ·  Chat  ·  Source

npm install lume

Features

LUME is composed of several packages that can be used individually, or together as a whole:

lume - HTML elements for rich graphics

HTML elements for easily defining rich and interactive 2D or 3D applications powered by CSS3D, WebGL, or a combination of both.

This package uses and re-exports features from the below packages.

@lume/element - System for defining HTML elements

This is a web component system that allows you to create new, fast, and performant HTML elements in a simple way. It provides the foundation for LUME's HTML elements, and a standard pattern for building new elements that extend the features of LUME.

element-behaviors - Mix functionalities onto HTML elements

This allows you to augment HTML elements with features called "behaviors" that are similar to custom elements: each behavior is defined as a class that has the same lifecycle methods as custom elements. The difference is that an unlimited number of behaviors can be associated with an element.

glas - WebGL engine written in AssemblyScript (WIP)

This is a WebGL engine with the consistent performance of WebAssembly, written in AssemblyScript (a TypeScript-to-WebAssembly compiler).

LUMECraft

LUMECraft is a collection of applications made with LUME, showing what LUME can do, and serving as forkable starting points for further customization.

first-person-shooter - First-person shooter game

A first-person shooter game foundation made with LUME, Solid.js, and Meteor.

Getting involved

There are various ways to get involved!

  • Visit the documentation and make something awesome!
  • Submit fixes or new features to any packages or the website! See the contributing guide.
  • Discuss LUME, get help, or help others in the forums or on our Discord chat server.

Status

tests

element-behaviors's People

Contributors

trusktr 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

element-behaviors's Issues

Should element behaviors be accessible on elements directly, or in a global map?

For example, should it be

const el = document.querySelector('div')

// suppose el is <div has="foo bar baz">

el.behaviors.add('click-logger')
el.behaviors.remove('foo')

// now el is <div has="bar baz click-logger">

which means .behaviors would exist on Element.prototype, or should it be something like

const el = document.querySelector('div')

// suppose el is <div has="foo bar baz">

elementBehaviors.of(el).add('click-logger')
elementBehaviors.of(el).remove('baz')

// now el is <div has="bar baz click-logger">

It seems like a global map would be easier to optimize, rather than increasing the size of the prototype of all elements by default. ?

Behaviors are not recognized for existing elements

Hi,

First of all, thanks for this library. I really love the concept and it is a nice, logical extensions of custom elements.

However, I found that the behaviors do not work if the element is added before the library load. The scripts we are using are automatically added as "defer" scripts to load in a non-blocking way (we do not have control over the loading mechanism of the scripts).

Is this a known issue of the library? Unfortunately if that's the case I likely won't be able to use the library, but I hope this will give some ideas to browser implementers :).

[question] has="" and storing data

I like the has="" attribute but I'm wondering if it doesn't make sense to go for "data-has". In the example with the player's position this makes even more sense to me. That way you can drop the dependency on custom attributes.

inheritance and dependencies?

Hi :)

I was taking a look at the spec and was wondering how easily I could migrate my code to the spec should it land.

For example, with most my Web components I use a mixin pattern. It's pretty similar with how the behavior systems.

Some mixins are rather simple, but some can get complex and even chain. For example, I have:

Each mixin takes a the custom element's class and extends it. It then goes to work. But some mixins will mixin another mixin before extending. For example, ControlMixin will mixin FormAssociatedMixin. InputMixin will mixin ControlMixin. That's pretty transitive. I imagine it's a matter of class ControlBehavior extends FormAssociatedBehavior.

But some mixins expect another mixin to have been applied first (dependencies). For example, my most complicated setup, I have three CustomElements:

They all reference TextFieldMixin which serves as branching point for mixins. Both XTextAreaElement and XSelectElement will use the ControlMixin, but XInputElement will use the InputMixin. They each also have a host of other mixins (like StateMixin).

This is mostly dealing with component definition, though runtime behaviors would definitely help with a mixin I have called TooltipTriggerMixin which I just apply to IconButton by default. It's better if it's done at runtime for any component.

Question 1:

What happens if a redundant behavior is listed?

<x-custominput has="themable state input textfield resizeobserver">
<x-custominput has="themable state control input textfield resizeobserver">

Question 2:

Do behaviors load after or before an element is defined? (I assuming before, or else how would observedAttributes work.)

Question 3:

Can behaviors be defaulted for elements? (Can behaviors be used to simplify Web Component design/definition). Once a component is finalized with its behaviors, I don't expect authors to have to include them each time.


Thanks for sharing your work with the public. If you're interested in taking a look at the mixin structure I'm talking about, I added links above. (The .mixin() and .extend() are just aliases which I find help write more declaratively, but everything can be rewritten in class/extend structure).

Infinite Loop Attaching Behavior

When connecting an input element I wrap the tag in a span and this causes the input element to be attached again in an infinite loop.

A temporary fix to this that I did was to change the code around this line:

if (!Behavior) return

with the following code:

if (!Behavior || (this.ownerElement._attached || []).includes(name))
        return;
const behavior = new Behavior(this.ownerElement);
if (!this.ownerElement._attached) {
  this.ownerElement._attached = []
}
this.ownerElement._attached.push(name)

Maybe there is a better solution? I don't know. But it works for now.

It is interesting to note that the version used in the code pen example in the docs doesn't have this behavior. It only occurs in the latest version.

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.