This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c443489
commit a0673b3
Showing
11 changed files
with
232 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,88 @@ | ||
### experiments with Angular and Web Components | ||
|
||
Nothing to see here yet :) | ||
Sketching out hosting Angular Components as Custom Elements / Web Components | ||
|
||
|
||
|
||
#### Angular Component API (4.x) | ||
|
||
Angular components are | ||
|
||
```ts | ||
|
||
//annotate with metadata about template and styles | ||
@Component({ | ||
selector: 'my-component', | ||
templateUrl: 'my-component.html', | ||
styleUrls: [ 'my-component.css' ], | ||
viewEncapsulation: ViewEncapsulation.Native //Shadow DOM V0 | ||
providers: [ SomeService ], | ||
|
||
}) | ||
class MyComponent { | ||
//public API for component consumers | ||
@Input() someProperty:any; //property values passed in | ||
@Output() someEvent new EventEmitter(); //events go out | ||
|
||
@ViewChild(ChildComponent) childView:ChildComponent; | ||
@ViewChildren(ItemComponent) items:QueryList<ItemComponent> | ||
|
||
//bind to host element events | ||
@HostListener('mousemove', ['$event']) | ||
onMouseMouse(event:MouseEvent){} | ||
|
||
//bind to host properties and attributes | ||
@HostBinding('attr.aria-foo') someValue; | ||
|
||
//lifecycle events | ||
ngOnInit(){} | ||
ngOnChanges(changes){} | ||
ngDoCheck(){} | ||
ngOnDestroy(){} | ||
|
||
//view lifecycle events | ||
ngAfterContentInit(){} | ||
ngAfterContentChecked(){} | ||
ngAfterViewInit(){} | ||
ngAfterViewChecked(){} | ||
|
||
|
||
} | ||
|
||
``` | ||
|
||
|
||
#### Custom Elements v1 API | ||
|
||
```ts | ||
|
||
class MyCustomElement extends HTMLElement { | ||
//newable | ||
constructor(...optionalArgs?:any[]){} | ||
|
||
//attributes to observe changes to | ||
static get observedAttributes():string[]{ return ['value', 'foo'] } | ||
|
||
//properties | ||
someProp:string; | ||
set foo(value:string) { } | ||
get foo() { return 'foo' } | ||
|
||
//dispatch events | ||
onClick(){ | ||
this.dispatchEvent(new CustomEvent('some-event', options)) | ||
} | ||
|
||
//called when attributes change | ||
attributeChangedCallback(attributeName, oldValue, newValue, namespace):void {} | ||
|
||
//called when connected to a document / shadow tree | ||
connectedCallback():void {} | ||
|
||
//called when removed from document | ||
disconnectedCallback():void {} | ||
|
||
} | ||
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Karma configuration | ||
// Generated on Wed Jun 28 2017 13:38:35 GMT-0700 (PDT) | ||
|
||
module.exports = function(config) { | ||
config.set({ | ||
|
||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
basePath: '', | ||
|
||
|
||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
frameworks: ['jasmine'], | ||
|
||
|
||
// list of files / patterns to load in the browser | ||
files: [ | ||
'public/es5-shim.js', | ||
'public/angular.js' | ||
], | ||
|
||
|
||
// list of files to exclude | ||
exclude: [ | ||
], | ||
|
||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: { | ||
}, | ||
|
||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['progress'], | ||
|
||
|
||
// web server port | ||
port: 9876, | ||
|
||
|
||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
|
||
|
||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
|
||
|
||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: true, | ||
|
||
|
||
// start these browsers | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: ['Chrome'], | ||
|
||
|
||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: false, | ||
|
||
// Concurrency level | ||
// how many browser should be started simultaneous | ||
concurrency: Infinity | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import nge from '../../custom_element_adapter' | ||
import {NgProgressBarNgFactory} from '../../ngfactory/src/demos/progress-bar/ng-progress-bar.ngfactory' | ||
import {ProgressBar} from './progress-bar' | ||
|
||
nge.define(NgProgressBarNgFactory); | ||
customElements.define('progress-bar', ProgressBar); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.