Skip to content

Commit d37aee0

Browse files
authored
Merge pull request #6 from tjmonsi/develop
Develop
2 parents 8aa4c37 + 5a76539 commit d37aee0

39 files changed

+6173
-2541
lines changed

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
sudo: required
22
addons:
3+
sauce_connect: true
4+
firefox: latest
35
chrome: stable
46
language: node_js
57
node_js:
@@ -10,6 +12,10 @@ before_install:
1012
before_script:
1113
- cp -r node_modules/lit-html ../../lit-html
1214
script: npm test && npm run wct-sauce
15+
branches:
16+
only:
17+
- master
18+
- develop
1319
env:
1420
global:
1521
- secure: IczLyQVw0rGAirfVHal4lcPNymjSQewhh2F8vu2rsp6ncNSAkSEVm9tXvSq47UkYzkLEUvi5l2rOIcmnfGsyjc8uCH3yFVpsMdoClP5W+2LO6XB7k6FyV3GXpfotEjKqIXqUWFosbFMdsV5X3zhuouckdvPcrY+QNltVl8P90JqGtVq5VqSIUZVhWsMxelrgY1p0iIx0YdftD0Hq8mip8ULztip+mbAAcLbUBOlOHHRdiG1cNp7GjpaBUPvtVY+/rDM8sgJ7SlK9F+BWsxj5If/Ky3n4HcyvvAAGeiqxJu0jxPQ37JwJKHligE5gK1O/piaAblSsy5kT4ElQXkxJLKLH8SQ7XViJ1NVGzh2AynDnx4J7PzWYfHKMYTbW2/6VaPOR/wr2xj1OdCRlNi8dK7y7Frhml9o58BakCDPx9zJgHd0s9lZQGdGA6O8DD6FpBwK9n8GqzEHI56phgtW8HH9T98r8ZSmm3iggwUesZo12kkkdc9/Eoe3X07G5cxq5r97E/rCnzhFz/uF786FX25H/pDIRUJ9K03VQuBMgG/vkFk1hzMEPjiFqFFXoa6odBR98OwbVFpR0JEpg4vcSRXDXfeNjxy1Pb2HXXSJAR9y2aCEW0U+IL4INPvK40igA/ijp16RP8TsLYszulzwxl8w8EvJTm0eJc1zlMc2QpZI=

.vscode/settings.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"__dirname",
2323
"URL",
2424
"describe",
25-
"it"
25+
"it",
26+
"expect",
27+
"assert"
2628
],
2729
"ignore": [
2830
"node_modules",
@@ -48,7 +50,10 @@
4850
"plugins": [
4951
"html"
5052
],
51-
"parser": "babel-eslint"
53+
"parser": "babel-eslint",
54+
"env": [
55+
"mocha"
56+
]
5257
},
5358
"standard.validate": [
5459
"javascript",

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# v0.1.3 (2018-18-03)
22
- Added more tests and created bundled versions for distribution
33
- Added CODE_OF_CONDUCT.md
4+
- updated to have Sauce labs tests
5+
- Updated README.md
46

57
# v0.1.1 (2018-15-03)
68
- Made a small fix on package.json on `main` to reflect main file

README.md

+188-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
# element-lite
2-
[![Build Status](https://travis-ci.org/tjmonsi/element-lite.svg?branch=master)](https://travis-ci.org/tjmonsi/element-lite)
2+
Master: [![Build Status](https://travis-ci.org/tjmonsi/element-lite.svg?branch=master)](https://travis-ci.org/tjmonsi/element-lite)
3+
Develop: [![Build Status](https://travis-ci.org/tjmonsi/element-lite.svg?branch=develop)](https://travis-ci.org/tjmonsi/element-lite)
34

45
A take on using lit-html and using methods coming from Polymer.
56

67
This is based on https://github.com/PolymerLabs/lit-element and added my own take on creating my own
7-
simple library.
8+
simple library. You can freely use it on your own projects.
89

9-
This is a work in progress but I will use it on my own projects. You can freely use it on your own projects.
10+
Most of the methods and its internals came from Polymer's properties-mixin, properties-changed, property-accessors mixin, and property-effects mixin (You can see each file on where parts are copied/modified from).
1011

11-
Most of the methods and its internals came from Polymer's properties-mixin, properties-changed, property-accessors mixin, and property-effects mixin.
12+
The reason for copying rather than depending on files is the added overhead of extending classes and
13+
the number of method overrides, making some inherited methods not used in the final part of
14+
upgrading the element. This is to squeeze out unused parts from the mixins.
1215

1316

1417
## How to install:
1518

16-
### using npm
19+
### Using npm
1720

1821
This is the recommended way. To install, just do this:
1922
```
2023
npm i --save @littleq/element-lite
2124
```
2225

2326

24-
25-
2627
## Out of the box, what can I do?
2728

29+
### On evergreen browsers that support ES6 and import (Latest Firefox and Chrome)
30+
2831
You can add this to your JS
2932

3033
```js
@@ -43,21 +46,71 @@ customElement.define('web-component', Component);
4346
and add this to your HTML
4447

4548
```html
46-
<script src="main.js" type="module">
49+
<script src="main.js" type="module"></script>
4750
```
4851

49-
You can also add these additional scripts for polyfill
52+
### Usage on bundlers like Webpack
53+
54+
Same as above.
55+
56+
### For non-Chrome evergreen browsers (Latest Firefox, Safari, and Edge)
57+
58+
You need to add this additional script for polyfill
5059

5160
```html
5261
<script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js">
5362
```
5463
55-
And if you are using Webpack and you have bundled it in ES5 for older browsers, you also need:
64+
And then wrap around the files after the `WebComponentsReady` event has been fired
65+
66+
```html
67+
<script>
68+
window.addEventListener('WebComponentsReady', function() {
69+
var component = document.createElement('script');
70+
component.src = 'main.js';
71+
component.type = 'module';
72+
document.head.appendChild(component);
73+
});
74+
</script>
75+
```
76+
77+
### If you compiled and bundled the elements to ES5
78+
79+
if you are using Webpack and you have bundled it in ES5 for older browsers, you also need:
5680

5781
```html
5882
<script src="node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js">
5983
```
6084
85+
### If you don't need a bundler but is capable for use in older browsers
86+
87+
```html
88+
<script src="/node_modules/@littleq/element-lite/dist/element-lite.umd.es5.min.js">
89+
<script>
90+
window.addEventListener('WebComponentsReady', function() {
91+
var component = document.createElement('script');
92+
component.src = 'main.js';
93+
document.head.appendChild(component);
94+
});
95+
</script>
96+
```
97+
98+
```js
99+
// main.js
100+
// wrap in anonymous function
101+
// Bundle this in ES5 either using Rollup or Webpack
102+
(function(){
103+
// get ElementLite from window.ElementLite;
104+
var ElementLite = window.ElementLite.ElementLite;
105+
class Component extends ElementLite(HTMLElement) {
106+
render () {
107+
return html`Whatever you want to put in the ShadowDom`;
108+
}
109+
}
110+
})();
111+
```
112+
113+
61114
## What else can it do?
62115

63116
You can put a default value on a property.
@@ -206,6 +259,7 @@ el.splice('prop1', 1, 0, '1', '2') // el.prop1 = ['a', '1', '2', 'b', 'c']
206259
el.splice('prop1', 1, 1) // el.prop1 = ['a', '2', 'b', 'c']
207260
```
208261

262+
209263
## Example usage
210264

211265
index.html
@@ -225,6 +279,7 @@ index.html
225279

226280
test-element.js
227281
```js
282+
// you can get lit-html's `html` from the bundle as well
228283
import { ElementLite, html } from './node_modules/@littleq/element-lite/element-lite.js';
229284
const { customElements } = window;
230285

@@ -319,6 +374,127 @@ class Component extends ElementLiteStaticShadow(HTMLElement) {
319374
customElement.define('web-component-static', Component);
320375
```
321376

377+
## Element-lite-lit-only
378+
379+
If you don't need the power of element-lite-base but need to the power of lit-html,
380+
use `element-lite-lit-only`
381+
382+
```js
383+
// main-static.js
384+
import { ElementLiteLitOnly } from 'node_modules/@littleq/element-lite/element-lite-lit-only.js'
385+
386+
class Component extends ElementLiteLitOnly(HTMLElement) {
387+
render () {
388+
return `Hello World!`
389+
}
390+
}
391+
392+
customElement.define('web-component-static', Component);
393+
```
394+
395+
396+
## What files to import and how?
397+
398+
If you are going to use it on Evergreen Browsers that allows `<script type="module">`,
399+
then you can just do this on your `js` files
400+
401+
```js
402+
import { ElementLite } from './node_modules/@littleq/element-lite/element-lite.js';
403+
```
404+
405+
If you are going to use it on Webpack or Rollup, you can do any of these
406+
407+
```js
408+
// provided that node_modules is resolved in your configurations
409+
import { ElementLite } from 'element-lite/@littleq/element-lite.js';
410+
```
411+
412+
or
413+
414+
```js
415+
import { ElementLite } from './node_modules/@littleq/element-lite';
416+
```
417+
418+
or
419+
420+
```js
421+
import { ElementLite } from './node_modules/@littleq/element-lite/dist/element-lite.esm.js';
422+
```
423+
424+
If you are going to use `require` and not `import` you can do any of these
425+
426+
```js
427+
// provided that node_modules is resolved in your configurations
428+
var ElementLite = require('@littleq/element-lite').ElementLite;
429+
```
430+
431+
or
432+
433+
```js
434+
// provided that node_modules is resolved in your configurations
435+
var ElementLite = require('@littleq/element-lite/dist/element-lite.cjs.js').ElementLite;
436+
```
437+
438+
If you are going to load it via the `<script>` tag, you need to do these
439+
440+
For ES6
441+
442+
```html
443+
<script src="/node_modules/@littleq/element-lite/dist/element-lite.umd.es6.js">
444+
<!-- <script src="/node_modules/@littleq/element-lite/dist/element-lite.umd.es6.min.js">
445+
if you need the minified file -->
446+
```
447+
448+
For ES5
449+
450+
```html
451+
<script src="/node_modules/@littleq/element-lite/dist/element-lite.umd.es5.js">
452+
<!-- <script src="/node_modules/@littleq/element-lite/dist/element-lite.umd.es5.min.js">
453+
if you need the minified file -->
454+
```
455+
456+
and then can access it here
457+
458+
```js
459+
var ElementLite = window.ElementLite.ElementLite
460+
```
461+
462+
You can also load ElementLiteBase, ElementLiteStaticShadow and ElementLiteLitOnly from ElementLite as well
463+
464+
```js
465+
// right from the box
466+
import { ElementLiteBase, ElementLiteStaticShadow, ElementLiteLitOnly } from './node_modules/element-lite/element-lite.js';
467+
```
468+
469+
using `require`
470+
471+
```js
472+
// provided that node_modules is resolved in your configurations
473+
var ElementLiteBase = require('@littleq/element-lite/dist/element-lite.cjs.js').ElementLiteBase;
474+
var ElementLiteStaticShadow = require('@littleq/element-lite/dist/element-lite.cjs.js').ElementLiteStaticShadow;
475+
var ElementLiteLitOnly = require('@littleq/element-lite/dist/element-lite.cjs.js').ElementLiteLitOnly;
476+
```
477+
478+
using `<script>`
479+
480+
```js
481+
var ElementLiteBase = window.ElementLite.ElementLiteBase
482+
var ElementLiteStaticShadow = window.ElementLite.ElementLiteStaticShadow
483+
var ElementLiteLitOnly = window.ElementLite.ElementLiteLitOnly
484+
```
485+
486+
487+
## And does it work on?
488+
489+
It works on all major evergreen Browsers (Edge, Safari, Chrome, Firefox) as long as you have the Polyfills
490+
set (make sure to add `webcomponents-lite` or `webcomponents-loader` and create the components after the
491+
`WebComponentsReady` event has been fired)
492+
493+
It also works on IE 11, Safari 11, Safari 10.1, Safari 9, and Safari 8.
494+
495+
Still checking on IE 10, 9, 8 and Safari 7, 6. (Need polyfills for `Map` and `WeakMap`).
496+
497+
322498
## Size
323499
324500
Based on size-limit
@@ -342,7 +518,7 @@ npm run size
342518
Size limit: 3 KB
343519
344520
element-lite.js
345-
Package size: 5.23 KB
521+
Package size: 5.33 KB
346522
Size limit: 5.5 KB
347523
348524
With all dependencies, minified and gzipped
@@ -352,4 +528,4 @@ npm run size
352528
353529
1. Not yet tested for Production #2
354530
2. Not yet tested using Webpack on older browsers #2
355-
4. Haven't tested a proper loop and if-then-else in #2
531+
3. Haven't tested a proper loop and if-then-else in #2

element-lite-base.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/// <reference path="typings-project/global.d.ts"/>
22

3+
import { dedupingMixin } from './lib/deduping-mixin.js';
4+
import { root, getProp, setProp, isPath } from './lib/path.js';
5+
import { saveAccessorValue } from './lib/save-accessor-value.js';
6+
import { camelToDashCase } from './lib/case-map.js';
7+
38
/**
49
* Parts are copied from different mixin parts of https://github.com/Polymer/polymer/tree/__auto_generated_3.0_preview
510
*
@@ -35,6 +40,10 @@
3540
* - HTMLElement Methods
3641
* - attributeChangedCallback - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/properties-changed.js#L379
3742
* - observedAttributes - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/properties-mixin.js#L85
43+
* - Public methods
44+
* - ready - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/properties-changed.js#L149
45+
* - set - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/property-effects.js#L1805
46+
*
3847
*
3948
*
4049
* - Modified
@@ -48,6 +57,13 @@
4857
* - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/properties-mixin.js#L160
4958
* - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/property-accessors.js#L112
5059
* - _invalidateProperties - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/properties-changed.js#L257
60+
* - Public Methods
61+
* - push - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/property-effects.js#L1831
62+
* - pop - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/property-effects.js#L1855
63+
* - splice - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/property-effects.js#L1883
64+
* - shift - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/property-effects.js#L1935
65+
* - unshift - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/property-effects.js#L1960
66+
* - get - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/property-effects.js#L1780
5167
* - Class Constructor - https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/mixins/properties-changed.js#L122
5268
*
5369
* - Created
@@ -58,11 +74,6 @@
5874
*
5975
*/
6076

61-
import { dedupingMixin } from './lib/deduping-mixin.js';
62-
import { root, getProp, setProp, isPath } from './lib/path.js';
63-
import { saveAccessorValue } from './lib/save-accessor-value.js';
64-
import { camelToDashCase } from './lib/case-map.js';
65-
6677
export const ElementLiteBase = dedupingMixin(base => {
6778
/**
6879
* Creates a copy of `props` with each property normalized such that

lib/case-map.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copied from https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/utils/case-map.js
2+
13
const caseMap = {};
24
// const DASH_TO_CAMEL = /-[a-z]/g;
35
const CAMEL_TO_DASH = /([A-Z])/g;

lib/deduping-mixin.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// @ts-check
22

3+
// Copied from https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/utils/mixin.js
4+
35
// unique global id for deduping mixins.
46
/** @type {number} */
57
let dedupeId = 0;

lib/path.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// @ts-check
22

3+
// Copied from https://github.com/Polymer/polymer/blob/__auto_generated_3.0_preview/lib/utils/path.js
4+
35
/**
46
* @param {string[]} path
57
* @return {string} normalized path

0 commit comments

Comments
 (0)