Skip to content

Commit

Permalink
Remerge: Resources/Mutator service refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
powerivq committed Feb 6, 2020
1 parent 439c12b commit de5accc
Show file tree
Hide file tree
Showing 11 changed files with 2,285 additions and 2,192 deletions.
28 changes: 18 additions & 10 deletions build-system/tasks/presubmit-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ const forbiddenTerms = {
'testing/iframe.js',
],
},
'installMutatorServiceForDoc': {
message: privateServiceFactory,
whitelist: [
'src/inabox/inabox-services.js',
'src/service/core-services.js',
'src/service/mutator-impl.js',
],
},
'installPerformanceService': {
message: privateServiceFactory,
whitelist: [
Expand All @@ -233,6 +241,14 @@ const forbiddenTerms = {
'src/service/performance-impl.js',
],
},
'installResourcesServiceForDoc': {
message: privateServiceFactory,
whitelist: [
'src/inabox/inabox-services.js',
'src/service/core-services.js',
'src/service/resources-impl.js',
],
},
'installStorageServiceForDoc': {
message: privateServiceFactory,
whitelist: [
Expand Down Expand Up @@ -284,15 +300,6 @@ const forbiddenTerms = {
'src/service/vsync-impl.js',
],
},
'installResourcesServiceForDoc': {
message: privateServiceFactory,
whitelist: [
'src/inabox/inabox-services.js',
'src/service/core-services.js',
'src/service/resources-impl.js',
'src/service/standard-actions-impl.js',
],
},
'installXhrService': {
message: privateServiceFactory,
whitelist: [
Expand Down Expand Up @@ -573,7 +580,7 @@ const forbiddenTerms = {
},
'\\.schedulePass\\(': {
message: 'schedulePass is heavy, think twice before using it',
whitelist: ['src/service/resources-impl.js'],
whitelist: ['src/service/mutator-impl.js', 'src/service/resources-impl.js'],
},
'\\.requireLayout\\(': {
message:
Expand Down Expand Up @@ -850,6 +857,7 @@ const forbiddenTerms = {
'test/unit/test-mode.js',
'test/unit/test-motion.js',
'test/unit/test-mustache.js',
'test/unit/test-mutator.js',
'test/unit/test-object.js',
'test/unit/test-observable.js',
'test/unit/test-pass.js',
Expand Down
13 changes: 10 additions & 3 deletions src/inabox/inabox-mutator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
*/

import {Services} from '../services';
import {registerServiceBuilderForDoc} from '../service';

/**
* @implements {../service/mutator-interface.MutatorInterface}
*/
export class InaboxMutator {
/**
* @param {!../service/ampdoc-impl.AmpDoc} ampdoc
* @param {!../service/resources-interface.ResourcesInterface} resources
*/
constructor(ampdoc, resources) {
constructor(ampdoc) {
/** @const @private {!../service/resources-interface.ResourcesInterface} */
this.resources_ = resources;
this.resources_ = Services.resourcesForDoc(ampdoc);

/** @private @const {!../service/vsync-impl.Vsync} */
this.vsync_ = Services./*OK*/ vsyncFor(ampdoc.win);
Expand Down Expand Up @@ -101,3 +101,10 @@ export class InaboxMutator {
});
}
}

/**
* @param {!../service/ampdoc-impl.AmpDoc} ampdoc
*/
export function installInaboxMutatorServiceForDoc(ampdoc) {
registerServiceBuilderForDoc(ampdoc, 'mutator', InaboxMutator);
}
59 changes: 8 additions & 51 deletions src/inabox/inabox-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import {Deferred} from '../utils/promise';
import {InaboxMutator} from './inabox-mutator';
import {Observable} from '../observable';
import {Pass} from '../pass';
import {READY_SCAN_SIGNAL} from '../service/resources-interface';
Expand Down Expand Up @@ -57,9 +56,6 @@ export class InaboxResources {
/** @const @private {!Deferred} */
this.firstPassDone_ = new Deferred();

/** @const @private {!InaboxMutator} */
this.mutator_ = new InaboxMutator(ampdoc, this);

const input = Services.inputFor(this.win);
input.setupInputModeClasses(ampdoc);
}
Expand Down Expand Up @@ -129,6 +125,12 @@ export class InaboxResources {
return this.pass_.schedule(opt_delay);
}

/** @override */
updateOrEnqueueMutateTask(unusedResource, unusedNewRequest) {}

/** @override */
schedulePassVsync() {}

/** @override */
onNextPass(callback) {
this.passObservable_.add(callback);
Expand All @@ -143,55 +145,10 @@ export class InaboxResources {
}

/** @override */
changeSize(element, newHeight, newWidth, opt_callback, opt_newMargins) {
this.mutator_./*OK*/ changeSize(
element,
newHeight,
newWidth,
opt_callback,
opt_newMargins
);
}
setRelayoutTop(unusedRelayoutTop) {}

/** @override */
attemptChangeSize(element, newHeight, newWidth, opt_newMargins) {
return this.mutator_.attemptChangeSize(
element,
newHeight,
newWidth,
opt_newMargins
);
}

/** @override */
expandElement(element) {
this.mutator_.expandElement(element);
}

/** @override */
attemptCollapse(element) {
return this.mutator_.attemptCollapse(element);
}

/** @override */
collapseElement(element) {
this.mutator_.collapseElement(element);
}

/** @override */
measureElement(measurer) {
return this.mutator_.measureElement(measurer);
}

/** @override */
mutateElement(element, mutator) {
return this.mutator_.mutateElement(element, mutator);
}

/** @override */
measureMutateElement(element, measurer, mutator) {
return this.mutator_.measureMutateElement(element, measurer, mutator);
}
maybeHeightChanged() {}

/**
* @return {!Promise} when first pass executed.
Expand Down
2 changes: 2 additions & 0 deletions src/inabox/inabox-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {installHiddenObserverForDoc} from '../service/hidden-observer-impl';
import {installHistoryServiceForDoc} from '../service/history-impl';
import {installIframeMessagingClient} from './inabox-iframe-messaging-client';
import {installInaboxCidService} from './inabox-cid';
import {installInaboxMutatorServiceForDoc} from './inabox-mutator';
import {installInaboxResourcesServiceForDoc} from './inabox-resources';
import {installInaboxViewerServiceForDoc} from './inabox-viewer';
import {installInaboxViewportService} from './inabox-viewport';
Expand All @@ -47,6 +48,7 @@ export function installAmpdocServicesForInabox(ampdoc) {
installHistoryServiceForDoc(ampdoc);
installInaboxResourcesServiceForDoc(ampdoc);
installOwnersServiceForDoc(ampdoc);
installInaboxMutatorServiceForDoc(ampdoc);
installUrlReplacementsServiceForDoc(ampdoc);
installActionServiceForDoc(ampdoc);
installStandardActionsForDoc(ampdoc);
Expand Down
4 changes: 4 additions & 0 deletions src/service/core-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {installHistoryServiceForDoc} from './history-impl';
import {installImg} from '../../builtins/amp-img';
import {installInputService} from '../input';
import {installLayout} from '../../builtins/amp-layout';
import {installMutatorServiceForDoc} from './mutator-impl';
import {installOwnersServiceForDoc} from './owners-impl';
import {installPixel} from '../../builtins/amp-pixel';
import {installPlatformService} from './platform-impl';
Expand Down Expand Up @@ -106,6 +107,9 @@ export function installAmpdocServices(ampdoc) {
isEmbedded
? adoptServiceForEmbedDoc(ampdoc, 'owners')
: installOwnersServiceForDoc(ampdoc);
isEmbedded
? adoptServiceForEmbedDoc(ampdoc, 'mutator')
: installMutatorServiceForDoc(ampdoc);
isEmbedded
? adoptServiceForEmbedDoc(ampdoc, 'url-replace')
: installUrlReplacementsServiceForDoc(ampdoc);
Expand Down
Loading

0 comments on commit de5accc

Please sign in to comment.