Skip to content

Commit

Permalink
refactor(util): remove getter functions for Polymer/ShadyCSS/customEl…
Browse files Browse the repository at this point in the history
…ements

BREAKING CHANGE:
The utility functions to get the Polymer/ShadyCSS/customElements properties have been removed. Instead typings are provided in the repo to access window.Polymer and window.ShadyCSS
  • Loading branch information
hotforfeature committed Mar 9, 2018
1 parent 3dbf3a4 commit c479759
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 62 deletions.
5 changes: 2 additions & 3 deletions origami/src/origami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ export * from './forms/iron-control.directive';
export * from './polymer.module';
export * from './style/shared-styles-host';
export * from './templates/polymer-template.directive';
export * from './util/customElements';
export * from './types/Polymer';
export * from './types/ShadyCSS';
export * from './util/descriptors';
export * from './util/getCustomElementClass';
export * from './util/getTagName';
export * from './util/Polymer';
export * from './util/ShadyCSS';
export * from './util/unwrapPolymerEvent';
export * from './util/webcomponents';
4 changes: 2 additions & 2 deletions origami/src/style/shared-styles-host.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Inject } from '@angular/core';
import { DOCUMENT, ɵDomSharedStylesHost as DomSharedStylesHost } from '@angular/platform-browser';

import { getShadyCSS } from '../util/ShadyCSS';
import '../types/ShadyCSS';

/**
* poylmer-webpack-loader will insert <style> and <custom-style> elements into the body, while
Expand Down Expand Up @@ -73,7 +73,7 @@ export class PolymerDomSharedStylesHost extends DomSharedStylesHost {

private addStylesToShadyCSS() {
// Importing Polymer will import ShadyCSS, but it is not required
const shadyCss = getShadyCSS();
const shadyCss = window.ShadyCSS;
if (shadyCss) {
this.hostNodes.forEach(hostNode => {
Array.from(hostNode.childNodes).forEach((childNode: Element) => {
Expand Down
4 changes: 2 additions & 2 deletions origami/src/templates/polymer-template.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import 'iron-list/iron-list.html';
import 'paper-checkbox/paper-checkbox.html';

import { getPolymer } from '../util/Polymer';
import '../types/Polymer';
import { unwrapPolymerEvent } from '../util/unwrapPolymerEvent';
import { PolymerTemplateDirective } from './polymer-template.directive';

Expand Down Expand Up @@ -77,7 +77,7 @@ describe('PolymerTemplateDirective', () => {
bindFixture.detectChanges();
bindFixture.whenStable().then(() => {
const ironList = bindFixture.debugElement.nativeElement.querySelector('iron-list');
getPolymer().RenderStatus.afterNextRender({}, () => {
window.Polymer.RenderStatus.afterNextRender({}, () => {
const checkboxes = Array.from(ironList.querySelectorAll('paper-checkbox'));
expect(checkboxes.length).toEqual(3);
bindFixture.componentInstance.ngChecked = true;
Expand Down
4 changes: 2 additions & 2 deletions origami/src/templates/polymer-template.directive.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// tslint:disable:no-string-literal
import { Directive, ElementRef, Input, NgZone, OnInit } from '@angular/core';

import '../types/Polymer';
import { wrapAndDefineDescriptor } from '../util/descriptors';
import { getPolymer } from '../util/Polymer';
import { unwrapPolymerEvent } from '../util/unwrapPolymerEvent';
import { webcomponentsReady } from '../util/webcomponents';

Expand Down Expand Up @@ -79,7 +79,7 @@ export class PolymerTemplateDirective implements OnInit {
if (templateInfo && templateInfo.hostProps) {
Object.keys(templateInfo.hostProps).forEach(hostProp => {
// Polymer -> Angular
const eventName = `_host_${getPolymer().CaseMap.camelToDashCase(hostProp)}-changed`;
const eventName = `_host_${window.Polymer.CaseMap.camelToDashCase(hostProp)}-changed`;
this.template.addEventListener(eventName, (e: CustomEvent) => {
this.zone.run(() => {
const value = unwrapPolymerEvent(e);
Expand Down
4 changes: 0 additions & 4 deletions origami/src/util/Polymer.ts → origami/src/types/Polymer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,3 @@ declare global {
Polymer: Polymer;
}
}

export function getPolymer(): Polymer {
return window.Polymer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ declare global {
ShadyCSS: ShadyCSS;
}
}

export function getShadyCSS(): ShadyCSS {
return window.ShadyCSS;
}
8 changes: 0 additions & 8 deletions origami/src/util/Polymer.spec.ts

This file was deleted.

21 changes: 0 additions & 21 deletions origami/src/util/ShadyCSS.spec.ts

This file was deleted.

8 changes: 0 additions & 8 deletions origami/src/util/customElements.spec.ts

This file was deleted.

3 changes: 0 additions & 3 deletions origami/src/util/customElements.ts

This file was deleted.

5 changes: 2 additions & 3 deletions origami/src/util/getCustomElementClass.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import 'polymer/polymer.html';

import { getCustomElements } from './customElements';
import '../types/Polymer';
import { getCustomElementClass } from './getCustomElementClass';
import { getPolymer } from './Polymer';

describe('getCustomElementClass()', () => {
it('should return constructor function for the element', () => {
const CustomElement = getPolymer()({ // tslint:disable-line:variable-name
const CustomElement = window.Polymer()({ // tslint:disable-line:variable-name
is: 'custom-element'
});

Expand Down
3 changes: 1 addition & 2 deletions origami/src/util/getCustomElementClass.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ElementRef } from '@angular/core';

import { getCustomElements } from './customElements';
import { getTagName } from './getTagName';

// tslint:disable-next-line:ban-types
export function getCustomElementClass(elementRef?: ElementRef): Function|void {
if (elementRef && elementRef.nativeElement) {
const klass = getCustomElements().get(elementRef.nativeElement.tagName.toLowerCase());
const klass = window.customElements.get(elementRef.nativeElement.tagName.toLowerCase());
if (klass) {
return klass;
} else {
Expand Down

0 comments on commit c479759

Please sign in to comment.