From 043a8862034ec2ee1def4df2055908a3a07fd306 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sat, 9 Jan 2021 12:30:33 -0600 Subject: [PATCH] Bring in fork changes (#92) * Bring in fork changes * Travis 8 test * Node 10 is supported these days * no fb * addon tests * revert --- vendor/document-title/document-title.js | 223 ++++++++++++------------ yarn.lock | 8 +- 2 files changed, 118 insertions(+), 113 deletions(-) diff --git a/vendor/document-title/document-title.js b/vendor/document-title/document-title.js index 2c872db..79248d6 100644 --- a/vendor/document-title/document-title.js +++ b/vendor/document-title/document-title.js @@ -1,117 +1,122 @@ -var get = Ember.get; -var getOwner = Ember.getOwner; -var Promise = Ember.RSVP.Promise; - -var routeProps = { - // `titleToken` can either be a static string or a function - // that accepts a model object and returns a string (or array - // of strings if there are multiple tokens). - titleToken: null, - - // `title` can either be a static string or a function - // that accepts an array of tokens and returns a string - // that will be the document title. The `collectTitleTokens` action - // stops bubbling once a route is encountered that has a `title` - // defined. - title: null, -}; - -/* - This is here because `_actions` was renamed to `actions` in Ember 2.0.0, but - we need it to work for versions before that. - - Here, we inspect the `Ember.Route` prototype, iterate over its - `mergedProperties` to see what is used, and then use that. - */ -var mergedActionPropertyName = (function() { - var routeProto = Ember.Route.proto(); - var mergedProps = routeProto.mergedProperties; - - for (var i = 0, l = mergedProps.length; i < l; i++) { - var property = mergedProps[i]; - - if (property === 'actions' || property === '_actions') { - return property; +;(function() { + var get = Ember.get; + var getOwner = Ember.getOwner; + var Promise = Ember.RSVP.Promise; + + var routeProps = { + // `titleToken` can either be a static string or a function + // that accepts a model object and returns a string (or array + // of strings if there are multiple tokens). + titleToken: null, + + // `title` can either be a static string or a function + // that accepts an array of tokens and returns a string + // that will be the document title. The `collectTitleTokens` action + // stops bubbling once a route is encountered that has a `title` + // defined. + title: null + }; + + /* + This is here because `_actions` was renamed to `actions` in Ember 2.0.0, but + we need it to work for versions before that. + + Here, we inspect the `Ember.Route` prototype, iterate over its + `mergedProperties` to see what is used, and then use that. + */ + var mergedActionPropertyName = (function() { + var routeProto = Ember.Route.proto(); + var mergedProps = routeProto.mergedProperties; + + for (var i = 0, l = mergedProps.length; i < l; i++) { + var property = mergedProps[i]; + + if (property === 'actions' || property === '_actions') { + return property; + } } - } -})(); + })(); -routeProps[mergedActionPropertyName] = { - collectTitleTokens: function(tokens) { - var titleToken = get(this, 'titleToken'); - if (typeof titleToken === 'function') { - titleToken = titleToken.call(this, get(this, 'currentModel')); - } + routeProps[mergedActionPropertyName] = { + collectTitleTokens: function(tokens) { + var titleToken = get(this, 'titleToken'); + if (typeof titleToken === 'function') { + titleToken = titleToken.call(this, get(this, 'currentModel')); + } - if (Ember.isArray(titleToken)) { - tokens.unshift.apply(tokens, titleToken); - } else if (titleToken) { - tokens.unshift(titleToken); - } + if (Ember.isArray(titleToken)) { + tokens.unshift.apply(tokens, titleToken); + } else if (titleToken) { + tokens.unshift(titleToken); + } - // If `title` exists, it signals the end of the - // token-collection, and the title is decided right here. - var title = get(this, 'title'); - if (title) { - var self = this; - - // Wrap in promise in case some tokens are asynchronous. - var completion = Promise.resolve() - .then(function() { - if (typeof title === 'function') { - // Wait for all tokens to resolve. It resolves immediately if all tokens are plain values (not promises). - return Promise.all(tokens).then(function(resolvedTokens) { - return title.call(self, resolvedTokens); - }); - } else { - // Tokens aren't even considered... a string - // title just sledgehammer overwrites any children tokens. - return title; - } - }) - .then(function(finalTitle) { - let router = getOwner(self).lookup('router:main'); - - // Stubbable fn that sets document.title - router.setTitle(finalTitle); - }); - - // Tell FastBoot about our async code - var fastboot = lookupFastBoot(this); - if (fastboot && fastboot.isFastBoot) { - fastboot.deferRendering(completion); + // If `title` exists, it signals the end of the + // token-collection, and the title is decided right here. + var title = get(this, 'title'); + if (title) { + var self = this; + + // Wrap in promise in case some tokens are asynchronous. + var completion = Promise.resolve() + .then(function() { + if (typeof title === 'function') { + // Wait for all tokens to resolve. It resolves immediately if all tokens are plain values (not promises). + return Promise.all(tokens).then(function(resolvedTokens) { + return title.call(self, resolvedTokens); + }); + } else { + // Tokens aren't even considered... a string + // title just sledgehammer overwrites any children tokens. + return title; + } + }) + .then(function(finalTitle) { + var router = + typeof getOwner === 'function' + ? getOwner(self).lookup('router:main') + : self.router; + + // Stubbable fn that sets document.title + router.setTitle(finalTitle); + }); + + // Tell FastBoot about our async code + var fastboot = lookupFastBoot(this); + if (fastboot && fastboot.isFastBoot) { + fastboot.deferRendering(completion); + } + } else { + // Continue bubbling. + return true; } - } else { - // Continue bubbling. - return true; } - }, -}; - -Ember.Route.reopen(routeProps); - -Ember.Router.reopen({ - updateTitle: Ember.on('didTransition', function() { - this.send('collectTitleTokens', []); - }), - - setTitle: function(title) { - var container = getOwner ? getOwner(this) : this.container; - var renderer = container.lookup('renderer:-dom'); - var domForAppWithGlimmer2 = container.lookup('service:-document'); - - if (renderer && renderer._dom) { - Ember.set(renderer, '_dom.document.title', title); - } else if (domForAppWithGlimmer2) { - // Glimmer 2 has a different renderer - Ember.set(domForAppWithGlimmer2, 'title', title); - } else { - document.title = title; + }; + + Ember.Route.reopen(routeProps); + + Ember.Router.reopen({ + updateTitle: Ember.on('didTransition', function() { + this.send('collectTitleTokens', []); + }), + + setTitle: function(title) { + var container = getOwner ? getOwner(this) : this.container; + var renderer = container.lookup('renderer:-dom'); + var domForAppWithGlimmer2 = container.lookup('service:-document'); + + if (renderer && renderer._dom) { + Ember.set(renderer, '_dom.document.title', title); + } else if (domForAppWithGlimmer2) { + // Glimmer 2 has a different renderer + Ember.set(domForAppWithGlimmer2, 'title', title); + } else { + document.title = title; + } } - }, -}); + }); -function lookupFastBoot(context) { - var container = getOwner ? getOwner(context) : context.container; - return container.lookup('service:fastboot'); -} + function lookupFastBoot(context) { + var container = getOwner ? getOwner(context) : context.container; + return container.lookup('service:fastboot'); + } +})(); diff --git a/yarn.lock b/yarn.lock index 9ff24f0..e7d754c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2736,10 +2736,10 @@ ember-export-application-global@^2.0.0: dependencies: ember-cli-babel "^6.0.0-beta.7" -ember-fastboot-addon-tests@^0.5.0: - version "0.5.0" - resolved "https://registry.yarnpkg.com/ember-fastboot-addon-tests/-/ember-fastboot-addon-tests-0.5.0.tgz#c7968c1d68e7828d85396873ebcb76355033c8d8" - integrity sha512-dsmnoCYyApXHs11iB8lrfAVvQTbXM62XB0NPFLJv5y18isw/Bpvb1RYF6NII4Gd3s7MbIykjcQC09e3HVEpKng== +ember-fastboot-addon-tests@^0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/ember-fastboot-addon-tests/-/ember-fastboot-addon-tests-0.5.1.tgz#a0af9d9c80b97ddc3e03481c08cdc78931394642" + integrity sha512-HpYYZ5HWp+i76wR3rJGJjDd2+YncKo5QkPiADTFkL0TdVU13yV8WowT1spxPQhtSa5N6HNQ9vcNb/ka1qIpVYQ== dependencies: chalk "^2.4.1" core-object "^3.1.5"