Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/client/queue-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as d from '../declarations';
export function createQueueClient(App: d.AppGlobal, win: Window): d.QueueApi {
const now: d.Now = () => win.performance.now();

const async = App.asyncQueue !== false;
const resolved = Promise.resolve();
const highPriority: d.RafCallback[] = [];
const domReads: d.RafCallback[] = [];
Expand Down Expand Up @@ -65,11 +66,13 @@ export function createQueueClient(App: d.AppGlobal, win: Window): d.QueueApi {
// DOM READS!!!
consume(domReads);

const start = now() + (7 * Math.ceil(congestion * (1.0 / 22.0)));
const timeout = async
? now() + (7 * Math.ceil(congestion * (1.0 / 22.0)))
: Infinity;

// DOM WRITES!!!
consumeTimeout(domWrites, start);
consumeTimeout(domWritesLow, start);
consumeTimeout(domWrites, timeout);
consumeTimeout(domWritesLow, timeout);

if (domWrites.length > 0) {
domWritesLow.push(...domWrites);
Expand Down
1 change: 1 addition & 0 deletions src/compiler/app/reserved-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const RESERVED_PROPERTIES: string[] = [
'ael',
'rel',
'raf',
'asyncQueue',
'read',
'ref',
'resourcesUrl',
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/bundle/derive-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function deriveModules(config: d.Config, compilerCtx: d.CompilerCtx
}
const modules = await Promise.all([
deriveModule(config, compilerCtx, buildCtx, 'es2017', true, true, moduleFormats.esm), // browser ES2017
deriveModule(config, compilerCtx, buildCtx, 'es2017', false, false, moduleFormats.esm), // esm ES2017
deriveModule(config, compilerCtx, buildCtx, 'es2017', false, false, moduleFormats.esm), // esm ES2017
deriveModule(config, compilerCtx, buildCtx, 'es5', false, true, moduleFormats.esm), // esm ES5
deriveModule(config, compilerCtx, buildCtx, 'es5', true, true, moduleFormats.amd), // browser ES5
]);
Expand Down
1 change: 1 addition & 0 deletions src/compiler/config/validate-outputs-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function validateOutputTargetAngular(config: d.Config) {

distOutputTargets.forEach(outputTarget => {
outputTarget.excludeComponents = outputTarget.excludeComponents || [];
outputTarget.useDirectives = !!outputTarget.useDirectives;

if (!path.isAbsolute(outputTarget.directivesProxyFile)) {
outputTarget.directivesProxyFile = normalizePath(path.join(config.rootDir, outputTarget.directivesProxyFile));
Expand Down
47 changes: 31 additions & 16 deletions src/compiler/distribution/dist-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function getComponents(excludeComponents: string[], cmpRegistry: d.ComponentRegi

async function angularDirectiveProxyOutput(config: d.Config, compilerCtx: d.CompilerCtx, outputTarget: d.OutputTargetAngular, cmpRegistry: d.ComponentRegistry) {
const components = getComponents(outputTarget.excludeComponents, cmpRegistry);
const { hasDirectives, hasOutputs, proxies } = generateProxies(components);
const useDirectives = outputTarget.useDirectives;
const { hasOutputs, proxies } = generateProxies(components, useDirectives);

const auxFunctions: string[] = [
inputsAuxFunction(),
Expand All @@ -37,10 +38,15 @@ async function angularDirectiveProxyOutput(config: d.Config, compilerCtx: d.Comp
'ElementRef'
];

if (hasDirectives) {
angularImports.push('Component');
angularImports.push('ViewEncapsulation');
angularImports.push('ChangeDetectionStrategy');
if (components.length > 0) {
if (useDirectives) {
angularImports.push('Directive');
} else {
angularImports.push('Component');
angularImports.push('ViewEncapsulation');
angularImports.push('ChangeDetectionStrategy');
angularImports.push('ChangeDetectorRef');
}
}

if (hasOutputs) {
Expand Down Expand Up @@ -111,15 +117,13 @@ export function proxyMethods(instance: any, el: any, methods: string[]) {
`;
}

function generateProxies(components: d.ComponentMeta[]) {
let hasDirectives = false;
function generateProxies(components: d.ComponentMeta[], useDirectives: boolean) {
let hasMethods = false;
let hasOutputs = false;
let hasInputs = false;

const lines = components.map(cmpMeta => {
const proxy = generateProxy(cmpMeta);
hasDirectives = true;
const proxy = generateProxy(cmpMeta, useDirectives);
if (proxy.hasInputs) {
hasInputs = true;
}
Expand All @@ -134,14 +138,13 @@ function generateProxies(components: d.ComponentMeta[]) {

return {
proxies: lines.join('\n'),
hasDirectives,
hasInputs,
hasMethods,
hasOutputs
};
}

function generateProxy(cmpMeta: d.ComponentMeta) {
function generateProxy(cmpMeta: d.ComponentMeta, useDirectives: boolean) {
// Collect component meta
const inputs = getInputs(cmpMeta);
const outputs = getOutputs(cmpMeta);
Expand All @@ -154,20 +157,25 @@ function generateProxy(cmpMeta: d.ComponentMeta) {
const hasContructor = hasInputs || hasOutputs || hasMethods;

// Generate Angular @Directive
const decorator = useDirectives ? 'Directive' : 'Component';
const directiveOpts = [
`selector: \'${cmpMeta.tagNameMeta}\'`,
`changeDetection: ChangeDetectionStrategy.OnPush`,
`encapsulation: ViewEncapsulation.None`,
`template: '<ng-content></ng-content>'`
];
if (!useDirectives) {
directiveOpts.push(
`changeDetection: ChangeDetectionStrategy.OnPush`,
`encapsulation: ViewEncapsulation.None`,
`template: '<ng-content></ng-content>'`
);
}
if (inputs.length > 0) {
directiveOpts.push(`inputs: ['${inputs.join(`', '`)}']`);
}

const tagNameAsPascal = dashToPascalCase(cmpMeta.tagNameMeta);
const lines = [`
export declare interface ${cmpMeta.componentClass} extends StencilComponents<'${tagNameAsPascal}'> {}
@Component({ ${directiveOpts.join(', ')} })
@${decorator}({ ${directiveOpts.join(', ')} })
export class ${cmpMeta.componentClass} {`];

// Generate outputs
Expand All @@ -177,9 +185,16 @@ export class ${cmpMeta.componentClass} {`];

// Generate component constructor
if (hasContructor) {
lines.push(`
if (useDirectives) {
lines.push(`
constructor(r: ElementRef) {
const el = r.nativeElement;`);
} else {
lines.push(`
constructor(c: ChangeDetectorRef, r: ElementRef) {
c.detach();
const el = r.nativeElement;`);
}
}

if (hasMethods) {
Expand Down
1 change: 1 addition & 0 deletions src/declarations/app-global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface WindowData extends Window {

export interface AppGlobal {
ael?: (elm: Element|Document|Window, eventName: string, cb: d.EventListenerCallback, opts?: d.ListenOptions) => void;
asyncQueue?: boolean;
resourcesUrl?: string;
componentOnReady?: (elm: d.HostElement, resolve: (elm: d.HostElement) => void) => boolean;
Context?: any;
Expand Down
1 change: 1 addition & 0 deletions src/declarations/output-targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export interface OutputTargetAngular extends OutputTargetBase {
directivesProxyFile?: string;
directivesArrayFile?: string;
excludeComponents?: string[];
useDirectives?: boolean;
}


Expand Down