Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Conversation

mgol
Copy link
Member

@mgol mgol commented Feb 14, 2018

Fixes #69

  • Please check if the PR fulfills these requirements
  • What modules are related to this pull-request
  • server side
  • client side
  • inline
  • build process
  • docs
  • tests
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

An API change.

  • What is the current behavior? (You can also link to an open issue here)

See #69

  • What is the new behavior (if this is a feature change)?

See #69

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Yes, but Preboot 6 requires a different way of importing inside of an Angular NgModule so people upgrading will have to change their imports anyway.

  • Other information:

Copy link
Member

@CaerusKaru CaerusKaru left a comment

Choose a reason for hiding this comment

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

You need to move the replay check to the EventReplayer to avoid adding more work for the end-users.

]
]).map(eventSelector => assign(eventSelector, {
// set `replay` to `true` if not specified
replay: eventSelector.replay != null ? eventSelector.replay : true
Copy link
Member

Choose a reason for hiding this comment

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

I hesitate about doing this here, since it's a lot of work for those adding their own selectors to always add replay. Can you add this logic to the event replayer instead?

Something like if(!!eventSelector.replay) instead of if(!eventSelector.noReplay)

Copy link
Member Author

Choose a reason for hiding this comment

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

This won’t be enough as undefinedis falsy. I’d have to compare to undefined explicitly. I’m a little afraid it might be fragile.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I misread your comment. You meant it’s work for consumers, not Prevoot code. I agree then.

@@ -111,9 +115,7 @@ export function getEventRecorderCode(): string {
* @param customOptions PrebootRecordOptions that override the defaults
* @returns Generated inline preboot code is returned
*/
export function getInlinePrebootCode(customOptions?: PrebootOptions): string {
const opts = <PrebootOptions>assign({}, defaultOptions, customOptions);
Copy link
Member

Choose a reason for hiding this comment

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

I don't want to move this because the Module is not the only consumer for this (ie React users may call it manually, and still want the default options)

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. Should I extend in both places or add an undefined check?

My concern with checking for undefined is that it breaks if the default changes.

Copy link
Member

Choose a reason for hiding this comment

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

When would the default change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it's not a big problem... Is extending in both places OK?

Copy link
Member

Choose a reason for hiding this comment

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

Why would we need it in both places if the inlinePrebootCode handles it anyway?

nonce: string|null,
platformId: Object,
appRef: ApplicationRef,
eventReplayer: EventReplayer) {
// necessary because of angular/angular/issues/14485
const res = () => {
// Use `Object.create(null)` as a base as otherwise user can modify
// the prototype of the options object.
const prebootOpts = <PrebootOptions>assign(Object.create(null), defaultOptions, customOpts);
Copy link
Member

Choose a reason for hiding this comment

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

This was a good idea, but in the future, since this is in the Angular module part of the app (and thus gets transpiled by the end user), you can just do an object spread here.

const prebootOpts = {...defaultOptions, ...customOpts};

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, I’ll update it.

Copy link
Member Author

@mgol mgol Feb 14, 2018

Choose a reason for hiding this comment

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

Actually, I can't do it as TypeScript's implementation of object spread is nonconformant and does regular assignments instead of Object.defineProperty and suffers from the same __proto__ prototype mutation issue as Object.assign with a regular object. :(

See here

Copy link
Member

Choose a reason for hiding this comment

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

I think if someone goes to the trouble to typecast an object to PrebootOptions and replace the __proto__, maybe they deserve to cause errors?

Copy link
Member

@CaerusKaru CaerusKaru left a comment

Choose a reason for hiding this comment

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

LGTM

@CaerusKaru CaerusKaru merged commit 3aff659 into angular:master Feb 14, 2018
@mgol mgol deleted the no-replay branch February 15, 2018 08:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename noReplay to replay
2 participants