Skip to content

Commit 373e58c

Browse files
manucorporatadamdbradley
authored andcommitted
fix(queue): allow option to disable async queue (#1186)
1 parent 6385239 commit 373e58c

7 files changed

Lines changed: 42 additions & 20 deletions

File tree

src/client/queue-client.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as d from '../declarations';
44
export function createQueueClient(App: d.AppGlobal, win: Window): d.QueueApi {
55
const now: d.Now = () => win.performance.now();
66

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

68-
const start = now() + (7 * Math.ceil(congestion * (1.0 / 22.0)));
69+
const timeout = async
70+
? now() + (7 * Math.ceil(congestion * (1.0 / 22.0)))
71+
: Infinity;
6972

7073
// DOM WRITES!!!
71-
consumeTimeout(domWrites, start);
72-
consumeTimeout(domWritesLow, start);
74+
consumeTimeout(domWrites, timeout);
75+
consumeTimeout(domWritesLow, timeout);
7376

7477
if (domWrites.length > 0) {
7578
domWritesLow.push(...domWrites);

src/compiler/app/reserved-properties.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const RESERVED_PROPERTIES: string[] = [
2929
'ael',
3030
'rel',
3131
'raf',
32+
'asyncQueue',
3233
'read',
3334
'ref',
3435
'resourcesUrl',

src/compiler/bundle/derive-modules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function deriveModules(config: d.Config, compilerCtx: d.CompilerCtx
1313
}
1414
const modules = await Promise.all([
1515
deriveModule(config, compilerCtx, buildCtx, 'es2017', true, true, moduleFormats.esm), // browser ES2017
16-
deriveModule(config, compilerCtx, buildCtx, 'es2017', false, false, moduleFormats.esm), // esm ES2017
16+
deriveModule(config, compilerCtx, buildCtx, 'es2017', false, false, moduleFormats.esm), // esm ES2017
1717
deriveModule(config, compilerCtx, buildCtx, 'es5', false, true, moduleFormats.esm), // esm ES5
1818
deriveModule(config, compilerCtx, buildCtx, 'es5', true, true, moduleFormats.amd), // browser ES5
1919
]);

src/compiler/config/validate-outputs-angular.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function validateOutputTargetAngular(config: d.Config) {
99

1010
distOutputTargets.forEach(outputTarget => {
1111
outputTarget.excludeComponents = outputTarget.excludeComponents || [];
12+
outputTarget.useDirectives = !!outputTarget.useDirectives;
1213

1314
if (!path.isAbsolute(outputTarget.directivesProxyFile)) {
1415
outputTarget.directivesProxyFile = normalizePath(path.join(config.rootDir, outputTarget.directivesProxyFile));

src/compiler/distribution/dist-angular.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ function getComponents(excludeComponents: string[], cmpRegistry: d.ComponentRegi
2626

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

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

40-
if (hasDirectives) {
41-
angularImports.push('Component');
42-
angularImports.push('ViewEncapsulation');
43-
angularImports.push('ChangeDetectionStrategy');
41+
if (components.length > 0) {
42+
if (useDirectives) {
43+
angularImports.push('Directive');
44+
} else {
45+
angularImports.push('Component');
46+
angularImports.push('ViewEncapsulation');
47+
angularImports.push('ChangeDetectionStrategy');
48+
angularImports.push('ChangeDetectorRef');
49+
}
4450
}
4551

4652
if (hasOutputs) {
@@ -111,15 +117,13 @@ export function proxyMethods(instance: any, el: any, methods: string[]) {
111117
`;
112118
}
113119

114-
function generateProxies(components: d.ComponentMeta[]) {
115-
let hasDirectives = false;
120+
function generateProxies(components: d.ComponentMeta[], useDirectives: boolean) {
116121
let hasMethods = false;
117122
let hasOutputs = false;
118123
let hasInputs = false;
119124

120125
const lines = components.map(cmpMeta => {
121-
const proxy = generateProxy(cmpMeta);
122-
hasDirectives = true;
126+
const proxy = generateProxy(cmpMeta, useDirectives);
123127
if (proxy.hasInputs) {
124128
hasInputs = true;
125129
}
@@ -134,14 +138,13 @@ function generateProxies(components: d.ComponentMeta[]) {
134138

135139
return {
136140
proxies: lines.join('\n'),
137-
hasDirectives,
138141
hasInputs,
139142
hasMethods,
140143
hasOutputs
141144
};
142145
}
143146

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

156159
// Generate Angular @Directive
160+
const decorator = useDirectives ? 'Directive' : 'Component';
157161
const directiveOpts = [
158162
`selector: \'${cmpMeta.tagNameMeta}\'`,
159-
`changeDetection: ChangeDetectionStrategy.OnPush`,
160-
`encapsulation: ViewEncapsulation.None`,
161-
`template: '<ng-content></ng-content>'`
162163
];
164+
if (!useDirectives) {
165+
directiveOpts.push(
166+
`changeDetection: ChangeDetectionStrategy.OnPush`,
167+
`encapsulation: ViewEncapsulation.None`,
168+
`template: '<ng-content></ng-content>'`
169+
);
170+
}
163171
if (inputs.length > 0) {
164172
directiveOpts.push(`inputs: ['${inputs.join(`', '`)}']`);
165173
}
166174

167175
const tagNameAsPascal = dashToPascalCase(cmpMeta.tagNameMeta);
168176
const lines = [`
169177
export declare interface ${cmpMeta.componentClass} extends StencilComponents<'${tagNameAsPascal}'> {}
170-
@Component({ ${directiveOpts.join(', ')} })
178+
@${decorator}({ ${directiveOpts.join(', ')} })
171179
export class ${cmpMeta.componentClass} {`];
172180

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

178186
// Generate component constructor
179187
if (hasContructor) {
180-
lines.push(`
188+
if (useDirectives) {
189+
lines.push(`
181190
constructor(r: ElementRef) {
182191
const el = r.nativeElement;`);
192+
} else {
193+
lines.push(`
194+
constructor(c: ChangeDetectorRef, r: ElementRef) {
195+
c.detach();
196+
const el = r.nativeElement;`);
197+
}
183198
}
184199

185200
if (hasMethods) {

src/declarations/app-global.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface WindowData extends Window {
2626

2727
export interface AppGlobal {
2828
ael?: (elm: Element|Document|Window, eventName: string, cb: d.EventListenerCallback, opts?: d.ListenOptions) => void;
29+
asyncQueue?: boolean;
2930
resourcesUrl?: string;
3031
componentOnReady?: (elm: d.HostElement, resolve: (elm: d.HostElement) => void) => boolean;
3132
Context?: any;

src/declarations/output-targets.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ export interface OutputTargetAngular extends OutputTargetBase {
193193
directivesProxyFile?: string;
194194
directivesArrayFile?: string;
195195
excludeComponents?: string[];
196+
useDirectives?: boolean;
196197
}
197198

198199

0 commit comments

Comments
 (0)