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

Sprint3 #22018

Closed
wants to merge 3 commits into from
Closed

Sprint3 #22018

wants to merge 3 commits into from

Conversation

mhevery
Copy link
Contributor

@mhevery mhevery commented Feb 5, 2018

PR Checklist

Please check if your PR fulfills the following requirements:

  • write unit test for markDirty
  • write unit test for detectChanges
  • write unit test for whenRendered
  • write unit test for withBody
  • write unit test and docs for ensureDocument
  • write unit test and docs for cleanupDocument
  • update patch_types_spec.ts with discussion per @chuckjaz (separate CL)
  • rework hell world bundle tests to use withBody

@IgorMinar & @chuckjaz Please check out patch_types_spec.ts if this is compatible with your understanding of the world.

/**
* GOALS:
* - Patch types in tree shakable way
* - Generate these types for files which have `matadatad.json` (since those are the files which
Copy link
Contributor

Choose a reason for hiding this comment

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

matadatad.json? Typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

await r3.whenRendered(todoApp);
expect(r3.getRenderedText(todoApp)).toEqual('...');
const firstCheckBox =
r3.getHostElement(todoApp).querySelector('input[type]=checkbox') as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

Broken selector?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

* Use this function to bootstrap a component into the DOM tree. Each invocation
* of this function will create a separate tree of components, injectors and
* change detection cycles and lifetimes. To dynamically insert a new component into
* existing tree such that it share the same injection, change detection and object
Copy link
Member

Choose a reason for hiding this comment

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

To dynamically insert a new component into an existing tree such that it shares the same injection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

* at some future point in time. This is because a single user action often results in many
* components being invalidated and calling change detection on each component synchronously
* would be inefficient. It is better to wait until all components re marked as dirty and
* than perform single change detection across all of the components.
Copy link
Member

Choose a reason for hiding this comment

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

until all components are marked as dirty and then perform

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

export function markDirty<T>(component: T) {
const rootContext = getRootContext(component);
let res: null|((val: null) => void);
if (!(res = rootContext.cleanResolve)) {
Copy link
Member

Choose a reason for hiding this comment

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

res shouldn't have to be assigned here, as its value is not used. In fact, res is only used within the if.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* @param component Component for which the host element should be retrieved.
*/
export function getHostElement<T>(component: T): HTMLElement {
return ((component as any)[NG_HOST_SYMBOL] as LElementNode).native as any;
Copy link
Member

Choose a reason for hiding this comment

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

Similar to getRootContext, this may benefit from ngDevMode asserts to verify the elementNode is present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* Retrieves the rendered text for a given component.
*
* This function retrieves the host element of a component and
* than returns the `textContent` for that element. This implies
Copy link
Member

Choose a reason for hiding this comment

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

and then returns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* adds HTML to the `body` element of the `document` and subsequently tears it down.
*
* This function is intended to be used with `async await` and `Promise`s. If the wrapped
* function returns a promise (or is `async`) than the teardown is delayed until that `Promise`
Copy link
Member

Choose a reason for hiding this comment

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

a promise (or is async) then the teardown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* function returns a promise (or is `async`) than the teardown is delayed until that `Promise`
* is resolved.
*
* On `node` this function detects if `document` is preset and if not it will create one by
Copy link
Member

Choose a reason for hiding this comment

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

detects if document is present and if not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -6,10 +6,10 @@
* found in the LICENSE file at https://angular.io/license
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider breaking this file into separate specs following the current nested defines, e.g. elements_spec.ts, component_and_directives_spec.ts, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is my plan, but I want to land this before I will break it up

@ngbot
Copy link

ngbot bot commented Feb 7, 2018

Hi @mhevery! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@mhevery mhevery force-pushed the sprint3 branch 2 times, most recently from 62c5469 to 2fcfa61 Compare February 8, 2018 06:55
*/
export function markDirty<T>(component: T) {
const rootContext = getRootContext(component);
if (!rootContext.cleanResolve) {
Copy link
Member

Choose a reason for hiding this comment

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

Come to think of it, we only use rootContext.cleanResolve as a marker to indicate if the context is marked dirty, the function itself is not called as such as it is captured by the scheduled action closure below. We might as well choose not to expose the resolve function in RootContext but only have a dirty flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, refactored

@ngbot
Copy link

ngbot bot commented Feb 8, 2018

Hi @mhevery! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@@ -157,9 +171,15 @@ export const NULL_INJECTOR: Injector = {


/**
* Bootstraps a Component into an existing host element and returns an instance
* Bootstraps a Component into an existing host element and return an instance
Copy link
Contributor

Choose a reason for hiding this comment

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

Intentional change? I think returns is actually clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

/**
* A function which is used to schedule change detection work in the future.
*
* When marking components as dirty it is necessary to schedule the work of
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing comma?

When marking components as dirty, it is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* of this function will create a separate tree of components, injectors and
* change detection cycles and lifetimes. To dynamically insert a new component
* into an existing tree such that it shares the same injection, change detection
* and object lifetime use {@link ViewContainer#createComponent}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing comma?

object lifetime, use ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

isDirty = true;
scheduler(() => detectChanges(component));
const lElementNode = (component as any)[NG_HOST_SYMBOL] as LElementNode;
ngDevMode && assertNotNull(lElementNode, 'Not a component!');
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace lines 274-275 with _getComponentHostElementNode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* This function returns a `Promise` which is resolved when the component's
* change detection is executed. This is determined by finding the scheduler
* associated with the `component`'s render tree and waiting until the scheduler
* flushes. If nothing is scheduled the function returns a resolved promise.
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing comma? If nothing is scheduled, the function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

cleanPromise: Promise<null>;

/**
* `clearPromise` resolution function when the change detection finishes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Name outdated in this comment? Re names, what do you think about markAsClean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed per #22018 (comment)

*
* This promise is overwritten every time a first call to {@link markDirty} is invoked.
*/
cleanPromise: Promise<null>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I read this the first time as "a promise that was clean" rather than "a promise that is resolved when components are clean". How about onClean or componentsClean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed per #22018 (comment)

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM

@mhevery mhevery added target: major This PR is targeted for the next major release action: merge The PR is ready for merge by the caretaker labels Feb 13, 2018
@mhevery mhevery force-pushed the sprint3 branch 4 times, most recently from 9e7252b to 479f694 Compare February 14, 2018 05:55
@trotyl
Copy link
Contributor

trotyl commented Feb 14, 2018

Sorry for an off-topic question, is there any plan to land the scheduler feature in markForCheck to current view engine (hope there's a codename for it as well), rather than relying on Zone-dependent onMicrotaskEmpty? That could help a lot for using Angular without loading Zone.js.

From the code seems that part has little coupling to ivy itself.

@mhevery
Copy link
Contributor Author

mhevery commented Feb 14, 2018

Sorry for an off-topic question, is there any plan to land the scheduler feature in markForCheck to current view engine (hope there's a codename for it as well), rather than relying on Zone-dependent onMicrotaskEmpty? That could help a lot for using Angular without loading Zone.js.

Yes, that is our plan, but we want to make sure that it is working well with Ivy before we back port it into ViewEngine

@mhevery mhevery added this to To do in Framework via automation Feb 14, 2018
@mhevery mhevery added the area: core Issues related to the framework runtime label Feb 14, 2018
@mhevery mhevery moved this from To do to In progress in Framework Feb 14, 2018
@mhevery mhevery moved this from In progress to in review in Framework Feb 14, 2018
@ngbot
Copy link

ngbot bot commented Feb 15, 2018

Hi @mhevery! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@mhevery mhevery force-pushed the sprint3 branch 2 times, most recently from ae11db5 to fb929d3 Compare February 15, 2018 00:40
@mhevery mhevery force-pushed the sprint3 branch 4 times, most recently from b521f8b to ffe68af Compare February 17, 2018 01:25
@mhevery
Copy link
Contributor Author

mhevery commented Feb 17, 2018

@vicb vicb closed this in 2654357 Feb 18, 2018
Framework automation moved this from in review to Done / Merged Feb 18, 2018
vicb pushed a commit that referenced this pull request Feb 18, 2018
jbogarthyde pushed a commit to jbogarthyde/angular that referenced this pull request Feb 23, 2018
jbogarthyde pushed a commit to jbogarthyde/angular that referenced this pull request Feb 23, 2018
jbogarthyde pushed a commit to jbogarthyde/angular that referenced this pull request Feb 23, 2018
smdunn pushed a commit to smdunn/angular that referenced this pull request Feb 28, 2018
smdunn pushed a commit to smdunn/angular that referenced this pull request Feb 28, 2018
smdunn pushed a commit to smdunn/angular that referenced this pull request Feb 28, 2018
@mhevery mhevery removed this from Done / Merged in Framework Mar 13, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
@kara kara added the comp: ivy label Feb 25, 2019
@ngbot ngbot bot added this to the needsTriage milestone Feb 25, 2019
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants