Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move owners implementation from resources to owners #23668

Merged
merged 3 commits into from
Aug 26, 2019

Conversation

powerivq
Copy link
Contributor

@powerivq powerivq commented Aug 2, 2019

TODO: Move unit tests.

src/service/owners-impl.js Outdated Show resolved Hide resolved
@powerivq powerivq force-pushed the owner-resources branch 2 times, most recently from 549c466 to 1bcb889 Compare August 2, 2019 22:18
src/service/owners-impl.js Outdated Show resolved Hide resolved
src/service/resources-impl.js Outdated Show resolved Hide resolved
import {isArray} from '../types';
import {registerServiceBuilderForDoc} from '../service';

const TAG_ = 'Owners';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: TAG

I know we use them interchangeably, but TAG without underscore is dominant.

* @param {!Element|!Array<!Element>} elements
* @return {!Array<!Element>}
*/
function elements_(elements) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, no underscore

schedulePreload(parentElement, subElements) {}
schedulePreload(parentElement, subElements) {
this.scheduleLayoutOrPreloadForSubresources_(
Resource.forElement(parentElement),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to reduce unnecessary dependency, use this.resources_.getResourcexxx to access this.

@powerivq powerivq force-pushed the owner-resources branch 2 times, most recently from 7db76a1 to 1a01b76 Compare August 2, 2019 23:13
/**
* @param {!Resource} resource
* @param {boolean} layout
* @param {number} parentPriority
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this param optional.

also, try to refactor the param to priorityOverride, which is a more generic and meaningful param for a public method.

@@ -262,6 +260,13 @@ export class ResourcesDef extends MutatorsAndOwnersDef {
*/
removeForChildWindow(childWin) {}

/**
* @param {!Resource} resource
* @param {boolean} layout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: layout => layoutNeeded

Copy link
Contributor

@lannka lannka Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, i think layoutNeeded is mis-leading. This boolean only controls the priority of the task.

we should refactor this boolean to isPreload (which is negate of the current boolean layout)

* @param {boolean} layout
* @param {number} parentPriority
*/
measureAndTrySchedule(resource, layout, parentPriority) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I meant measureAndTryScheduleLayout

@powerivq powerivq force-pushed the owner-resources branch 3 times, most recently from 6788a7b to 69d93e3 Compare August 16, 2019 17:24
@powerivq powerivq changed the title [WIP] Move owners implementation from resources to owners Move owners implementation from resources to owners Aug 16, 2019
@powerivq powerivq requested a review from lannka August 16, 2019 17:56
* @interface
*/
export class Owners {
export class OwnersDef {
Copy link
Contributor

@lannka lannka Aug 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to unify all the service interface names to XXXInterface, and move it out to its own file owners-interface.js

/**
* @implements {OwnersDef}
*/
export class Owners {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@visibleForTesting

Owners => OwnersImpl

import {Signals} from '../../src/utils/signals';
import {layoutRectLtwh} from '../../src/layout-rect';

/*eslint "google-camelcase/google-camelcase": 0*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment what is this for

resource.getState() === ResourceState.READY_FOR_LAYOUT &&
resource.isDisplayed()
) {
this.scheduleLayoutOrPreload_(resource, !isPreload, opt_parentPriority);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked every call site to ensure that isPreload is the opposite of what it was? Why are we flipping it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Affirm that. The only reason is that we are making this an interface, and it needs to be a bit more readable.

@lannka
Copy link
Contributor

lannka commented Aug 22, 2019

@powerivq any blockers to this PR?

@powerivq powerivq force-pushed the owner-resources branch 3 times, most recently from 378b86d to 748e3b8 Compare August 23, 2019 22:52
@powerivq
Copy link
Contributor Author

@jridgewell Looked into the binary. The primary cause of increase is because we made two new public interfaces, and therefore their method names are no longer obfuscated.

Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trusting that the methods are copy-pasted with only the preload change.

@powerivq powerivq merged commit 9ec6117 into ampproject:master Aug 26, 2019
@powerivq powerivq deleted the owner-resources branch August 26, 2019 20:14
thekorn pushed a commit to edelight/amphtml that referenced this pull request Sep 11, 2019
* Move owners implementation from resources to owners

* Refactor discoverElements

* Fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants