Skip to content

feat: set document lang attribute#649

Merged
buschtoens merged 6 commits into
masterfrom
feat/533-html-lang
Oct 24, 2018
Merged

feat: set document lang attribute#649
buschtoens merged 6 commits into
masterfrom
feat/533-html-lang

Conversation

@buschtoens

Copy link
Copy Markdown
Member

Closes #533.

Based on the code provided by @Turbo87 in #533 (comment)

@buschtoens buschtoens requested a review from Turbo87 October 23, 2018 09:45
Comment thread addon/services/intl.js Outdated
if (!isArrayEqual(proposed, this._locale)) {
this._locale = proposed;
this.trigger('localeChanged');
next(() => this.trigger('localeChanged'));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The locale does not actually change until after this setter has run through. So emitting this event during the setter causes all (synchronous) listeners accessing the locale property to receive the old value.

The reason that it works in the {{t}} helper is that recompute marks the helper as dirty and it's only recomputed later in a different run loop queue.

this.intl.on('localeChanged', this, this.recompute);

I only noticed this "bug" now, because I used the event further down in the class.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this should be an independent bugfix PR then, right? I guess it would also be good to have some sort of test for this so that we don't regress on this again.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll pull it out. 👌

Comment thread addon/services/intl.js Outdated
},

/** @private **/
updateDocumentLanguage: on('localeChanged', function() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do you use the Evented system for this instead of calling updateDocumentLanguage() directly from the setter?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because it was already there and (in theory) usable. Assuming that localeChanged was implemented correctly in the first place, this would have been a "minimally invasive" addition. 😄

Doing it this way also allows us to potentially add further listeners, without having to explicitly list them all.

But on second thought, I think you are right. The Evented thing is foreseen to be deprecated at some point (AFAIK) and the order the listeners would wbe called in is not explicitly defined.

I'll refactor it.

@Turbo87 Turbo87 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems good to me. we don't have any fastboot tests in here so far, right?

@jasonmit

Copy link
Copy Markdown
Member

@Turbo87 correct, no fastboot tests at the moment.

@jasonmit

Copy link
Copy Markdown
Member

@buschtoens I made some adjustments to fix the failing test and rebased. Merge whenever you're ready.

@jasonmit jasonmit self-requested a review October 24, 2018 04:19
@buschtoens

Copy link
Copy Markdown
Member Author

Awesome, thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants