Upgrade Ember to 2.13

This commit is contained in:
Robin Ward 2017-06-13 15:52:08 -04:00
parent ac1f84d3e1
commit 8ae445766f
11 changed files with 52 additions and 22 deletions

View File

@ -101,7 +101,7 @@ GEM
ember-source (>= 1.1.0)
jquery-rails (>= 1.0.17)
railties (>= 3.1)
ember-source (2.10.2)
ember-source (2.13.3)
erubis (2.7.0)
excon (0.56.0)
execjs (2.7.0)

View File

@ -15,7 +15,11 @@ export function getRegister(obj) {
const register = {
lookup: (...args) => owner.lookup(...args),
lookupFactory: (...args) => {
return owner.lookupFactory ? owner.lookupFactory(...args) : owner._lookupFactory(...args);
if (owner.factoryFor) {
return owner.factoryFor(...args);
} else if (owner._lookupFactory) {
return owner._lookupFactory(...args);
}
},
deprecateContainer(target) {

View File

@ -22,7 +22,7 @@ import { attachAdditionalPanel } from 'discourse/widgets/header';
// If you add any methods to the API ensure you bump up this number
const PLUGIN_API_VERSION = '0.8.6';
const PLUGIN_API_VERSION = '0.8.7';
class PluginApi {
constructor(version, container) {
@ -39,6 +39,25 @@ class PluginApi {
return this.container.lookup('current-user:main');
}
/**
* Allows you to overwrite or extend methods in a class.
*
* For example:
*
* ```
* api.modifyClass('controller:composer', {
* actions: {
* newActionHere() { }
* }
* });
* ```
**/
modifyClass(resolverName, changes) {
const klass = this.container.factoryFor(resolverName);
klass.class.reopen(changes);
return klass;
}
/**
* Used for decorating the `cooked` content of a post after it is rendered using
* jQuery.
@ -61,7 +80,7 @@ class PluginApi {
if (!opts.onlyStream) {
decorate(ComposerEditor, 'previewRefreshed', callback);
decorate(this.container.lookupFactory('component:user-stream'), 'didInsertElement', callback);
decorate(this.container.factoryFor('component:user-stream').class, 'didInsertElement', callback);
}
}
@ -170,7 +189,7 @@ class PluginApi {
* ```
**/
attachWidgetAction(widget, actionName, fn) {
const widgetClass = this.container.lookupFactory(`widget:${widget}`);
const widgetClass = this.container.factoryFor(`widget:${widget}`).class;
widgetClass.prototype[actionName] = fn;
}

View File

@ -367,7 +367,7 @@ const DiscourseURL = Ember.Object.extend({
discoveryTopics.resetParams();
}
router.router.updateURL(path);
router._routerMicrolib.updateURL(path);
}
const split = path.split('#');

View File

@ -31,7 +31,7 @@ const Scrolling = Ember.Mixin.create({
opts = opts || { debounce: 100 };
// So we can not call the scrolled event while transitioning
const router = Discourse.__container__.lookup('router:main').router;
const router = Discourse.__container__.lookup('router:main')._routerMicrolib;
let onScrollMethod = () => {
if (router.activeTransition) { return; }

View File

@ -297,7 +297,16 @@ export default Ember.Object.extend({
if (existing) {
delete obj.id;
const klass = this.register.lookupFactory('model:' + type) || RestModel;
let klass = this.register.lookupFactory('model:' + type);
if (klass && klass.class) {
klass = klass.class;
}
if (!klass) {
klass = RestModel;
}
existing.setProperties(klass.munge(obj));
obj.id = id;
return existing;

View File

@ -248,6 +248,9 @@ export default class Widget {
return;
}
WidgetClass = this.register.lookupFactory(`widget:${widgetName}`);
if (WidgetClass && WidgetClass.class) {
WidgetClass = WidgetClass.class;
}
}
if (WidgetClass) {

View File

@ -11,8 +11,7 @@ function initializeDetails(api) {
};
});
const ComposerController = api.container.lookupFactory("controller:composer");
ComposerController.reopen({
api.modifyClass('controller:composer', {
actions: {
insertDetails() {
this.get("toolbarEvent").applySurround(
@ -31,6 +30,6 @@ export default {
name: "apply-details",
initialize() {
withPluginApi('0.5', initializeDetails);
withPluginApi('0.8.7', initializeDetails);
}
};

View File

@ -4,9 +4,8 @@ function initialize(api) {
const messageBus = api.container.lookup('message-bus:main');
const currentUser = api.getCurrentUser();
const appEvents = api.container.lookup('app-events:main');
const SiteHeaderComponent = api.container.lookupFactory('component:site-header');
SiteHeaderComponent.reopen({
api.modifyClass('component:site-header', {
didInsertElement() {
this._super();
this.dispatch('header:search-context-trigger', 'header');
@ -34,6 +33,6 @@ export default {
initialize(container) {
const siteSettings = container.lookup('site-settings:main');
if (siteSettings.discourse_narrative_bot_enabled) withPluginApi('0.5', initialize);
if (siteSettings.discourse_narrative_bot_enabled) withPluginApi('0.8.7', initialize);
}
};

View File

@ -6,8 +6,7 @@ function initializePollUIBuilder(api) {
if (!siteSettings.poll_enabled && (api.getCurrentUser() && !api.getCurrentUser().staff)) return;
const ComposerController = api.container.lookupFactory("controller:composer");
ComposerController.reopen({
api.modifyClass('controller:composer', {
actions: {
showPollBuilder() {
showModal("poll-ui-builder").set("toolbarEvent", this.get("toolbarEvent"));
@ -28,6 +27,6 @@ export default {
name: "add-poll-ui-builder",
initialize() {
withPluginApi('0.5', initializePollUIBuilder);
withPluginApi('0.8.7', initializePollUIBuilder);
}
};

View File

@ -6,8 +6,7 @@ import WidgetGlue from 'discourse/widgets/glue';
function initializePolls(api) {
const register = getRegister(api);
const TopicController = api.container.lookupFactory('controller:topic');
TopicController.reopen({
api.modifyClass('controller:topic', {
subscribe(){
this._super();
this.messageBus.subscribe("/polls/" + this.get("model.id"), msg => {
@ -23,8 +22,7 @@ function initializePolls(api) {
}
});
const Post = api.container.lookupFactory('model:post');
Post.reopen({
api.modifyClass('model:post', {
_polls: null,
pollsObject: null,
@ -95,6 +93,6 @@ export default {
name: "extend-for-poll",
initialize() {
withPluginApi('0.1', initializePolls);
withPluginApi('0.8.7', initializePolls);
}
};