Giter Site home page Giter Site logo

shadow-query's Introduction

shadow-query

Micro-library for writing vanilla web components

ShadowQuery is a tiny (2k uglified gzip, some 350 lines of code without comments and new lines as of this writing) utility library to help develop high performance vanilla web components. Some of its API syntax is reminiscent of web dev warhorse jQuery, adapted for working with Shadow DOM, hence the name.

Tiny: demo/dbmonster.html is a selfcontained HTML app below 10K (load without server into your Chrome or Firefox, for other browsers you may need to add more polyfills).

High Performance: shadow-query dbmonster is among the fastest dbmonsters out there, one of the lowest memory footprints.

... and all that at 100 lines of nicely structured code plus templates

<!DOCTYPE html>
<html>
	<head><script type="module">
		import $ from '../shadowQuery.mjs';

		const template = `
			<style>:host {
				cursor: pointer;
				font-family: sans-serif;
			}</style>
			<h3><slot></slot></h3>
			<ul></ul>
		`;

		window.customElements.define('hello-framework', class extends HTMLElement {
			constructor() {
				super();
				$(this).on('click', () => alert('ShadowQuery loves you!'));
			}
			connectedCallback() {
				$(this).shadow(template);
				$(this, 'ul').append({
					array   : $(this, ':host').attr('greet').split(' '),
					template: '<li> </li>',
					update  : (li, item) => li.text(`Hello ${item}!`),
				});
			}
		});
	</script></head>
	<body>
		<hello-framework greet="Angular React Vue">Greetings!</hello-framework>
	</body>
</html>

This works as is in Chrome, for other browsers you may need to load polyfills until they fully support the standart. Everything that starts with $ above is ShadowQuery, the rest ist standart tech. The result of the above is:

Greetings!

  • Hello Angular!
  • Hello React!
  • Hello Vue!

... and that example renders so fast, it's hard to find the 3ms time for rendering between the other stuff Chrome does on page start up.

Installation

npm i -s 'shadow-query'

Status

ShadowQuery is currently a proof of concept. I have developed one smallish (1.5k lines) web application on it. ShadowQuery now comes with a test suite that covers 100% of the lines of code. I would not recommend it for production, it needs more testing.

Intended Audience

If you're the Visual Basic Angular/React kind of dev, ShadowQuery is not for you. It does not hold your hand, it does not structure your project. ShadowQuery is for you (or would be if it had outgrown experimental status), if you like to be in control, if you know what you're doing. It has zero magic, no surprises … actually, one thing did surprise me: you really need very little utility to empower you to write vanilly web components and make full use of the platform.

shadow-query's People

Contributors

schrotie avatar

Stargazers

Fredrik Ekelund avatar Price Smith avatar SHΛRPCODΞ.PRO avatar BlindPenguin avatar Colton Colcleasure avatar  avatar Lee Peterson avatar Salvatore avatar kamesh sethupathi avatar Vincent Ogloblinsky avatar Csaba Toth avatar

Watchers

 avatar SHΛRPCODΞ.PRO avatar

Forkers

78nine

shadow-query's Issues

Exception when code is minified

Line 461 if(nodes.name == 'processDynNodes') does not work when the module is minified because name is mangled by the minifier.

This is explained in: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#JavaScript_compressors_and_minifiers

In essence you can't reliably use Function.name in production code.

My hacky fix is:

function dynTemplate(template) { 
/*return */ function processDynNodes(parent, callback) { ... }
    processDynNodes._name = 'processDynNodes';
    return processDynNodes;
}

and in:

function toNodes(parent, nodes, callback) {
...
	if(nodes._name == 'processDynNodes') return nodes(parent, callback);

}

A cleaner solution would IMO be better.

BTW I'm using aria-tabs and discovered this issue when I was about to do release. Thanks for aria-tabs etc.

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.