ES6 module migrations

This commit is contained in:
Robin Ward 2015-04-08 14:17:21 -04:00
parent 22ffcba8e6
commit a83a19f6ce
27 changed files with 109 additions and 124 deletions

View File

@ -1,6 +1,7 @@
import Presence from 'discourse/mixins/presence';
import { outputExportResult } from 'discourse/lib/export-result'; import { outputExportResult } from 'discourse/lib/export-result';
export default Ember.ArrayController.extend(Discourse.Presence, { export default Ember.ArrayController.extend(Presence, {
loading: false, loading: false,
actions: { actions: {

View File

@ -1,6 +1,7 @@
import Presence from 'discourse/mixins/presence';
import { outputExportResult } from 'discourse/lib/export-result'; import { outputExportResult } from 'discourse/lib/export-result';
export default Ember.ArrayController.extend(Discourse.Presence, { export default Ember.ArrayController.extend(Presence, {
loading: false, loading: false,
itemController: 'admin-log-screened-ip-address', itemController: 'admin-log-screened-ip-address',
filter: null, filter: null,

View File

@ -1,6 +1,7 @@
import Presence from 'discourse/mixins/presence';
import { outputExportResult } from 'discourse/lib/export-result'; import { outputExportResult } from 'discourse/lib/export-result';
export default Ember.ArrayController.extend(Discourse.Presence, { export default Ember.ArrayController.extend(Presence, {
loading: false, loading: false,
show() { show() {

View File

@ -1,6 +1,7 @@
import Presence from 'discourse/mixins/presence';
import { outputExportResult } from 'discourse/lib/export-result'; import { outputExportResult } from 'discourse/lib/export-result';
export default Ember.ArrayController.extend(Discourse.Presence, { export default Ember.ArrayController.extend(Presence, {
loading: false, loading: false,
filters: null, filters: null,

View File

@ -1,4 +1,6 @@
export default Ember.ArrayController.extend(Discourse.Presence, { import Presence from 'discourse/mixins/presence';
export default Ember.ArrayController.extend(Presence, {
filter: null, filter: null,
onlyOverridden: false, onlyOverridden: false,
filtered: Ember.computed.notEmpty('filter'), filtered: Ember.computed.notEmpty('filter'),

View File

@ -1 +1,3 @@
export default Ember.Controller.extend(Discourse.Presence); import Presence from 'discourse/mixins/presence';
export default Ember.Controller.extend(Presence);

View File

@ -1 +1,3 @@
export default Ember.ObjectController.extend(Discourse.Presence); import Presence from 'discourse/mixins/presence';
export default Ember.ObjectController.extend(Presence);

View File

@ -1,8 +1,9 @@
import Presence from 'discourse/mixins/presence';
import searchForTerm from 'discourse/lib/search-for-term'; import searchForTerm from 'discourse/lib/search-for-term';
var _dontSearch = false; var _dontSearch = false;
export default Em.Controller.extend(Discourse.Presence, { export default Em.Controller.extend(Presence, {
contextType: function(key, value){ contextType: function(key, value){
if(arguments.length > 1) { if(arguments.length > 1) {

View File

@ -1,36 +0,0 @@
/**
This mixin provides `blank` and `present` to determine whether properties are
there, accounting for more cases than just null and undefined.
@class Discourse.Presence
@extends Ember.Mixin
@namespace Discourse
@module Discourse
**/
Discourse.Presence = Em.Mixin.create({
/**
Returns whether a property is blank. It considers empty arrays, string, objects, undefined and null
to be blank, otherwise true.
@method blank
@param {String} name the name of the property we want to check
@return {Boolean}
*/
blank: function(name) {
return Ember.isEmpty(this[name] || this.get(name));
},
/**
Returns whether a property is present. A present property is the opposite of a `blank` one.
@method present
@param {String} name the name of the property we want to check
@return {Boolean}
*/
present: function(name) {
return !this.blank(name);
}
});

View File

@ -0,0 +1,20 @@
/**
This mixin provides `blank` and `present` to determine whether properties are
there, accounting for more cases than just null and undefined.
**/
export default Ember.Mixin.create({
/**
Returns whether a property is blank. It considers empty arrays, string, objects, undefined and null
to be blank, otherwise true.
*/
blank(name) {
return Ember.isEmpty(this[name] || this.get(name));
},
// Returns whether a property is present. A present property is the opposite of a `blank` one.
present(name) {
return !this.blank(name);
}
});

View File

@ -1,6 +1,8 @@
Discourse.Model = Ember.Object.extend(Discourse.Presence); import Presence from 'discourse/mixins/presence';
Discourse.Model.reopenClass({ const Model = Ember.Object.extend(Presence);
Model.reopenClass({
extractByKey: function(collection, klass) { extractByKey: function(collection, klass) {
var retval = {}; var retval = {};
if (Ember.isEmpty(collection)) { return retval; } if (Ember.isEmpty(collection)) { return retval; }
@ -11,3 +13,5 @@ Discourse.Model.reopenClass({
return retval; return retval;
} }
}); });
export default Model;

View File

@ -1,4 +1,6 @@
const Post = Discourse.Model.extend({ import RestModel from 'discourse/models/rest';
const Post = RestModel.extend({
init() { init() {
this.set('replyHistory', []); this.set('replyHistory', []);

View File

@ -1,4 +1,6 @@
export default Ember.Object.extend({ import Presence from 'discourse/mixins/presence';
export default Ember.Object.extend(Presence, {
update(attrs) { update(attrs) {
const self = this, const self = this,
type = this.get('__type'); type = this.get('__type');

View File

@ -1,4 +1,6 @@
export default Ember.ContainerView.extend(Discourse.Presence, { import Presence from 'discourse/mixins/presence';
export default Ember.ContainerView.extend(Presence, {
attachViewWithArgs(viewArgs, viewClass) { attachViewWithArgs(viewArgs, viewClass) {
if (!viewClass) { viewClass = Ember.View.extend(); } if (!viewClass) { viewClass = Ember.View.extend(); }

View File

@ -0,0 +1,12 @@
import Presence from 'discourse/mixins/presence';
export default Ember.View.extend(Presence, {
_groupInit: function() {
this.set('context', this.get('content'));
const templateData = this.get('templateData');
if (templateData) {
this.set('templateData.insideGroup', true);
}
}.on('init')
});

View File

@ -1,52 +0,0 @@
/**
A base view that gives us common functionality, for example `present` and `blank`
@class View
@extends Ember.View
@uses Discourse.Presence
@namespace Discourse
@module Discourse
**/
Discourse.View = Ember.View.extend(Discourse.Presence, {});
Discourse.GroupedView = Ember.View.extend(Discourse.Presence, {
init: function() {
this._super();
this.set('context', this.get('content'));
var templateData = this.get('templateData');
if (templateData) {
this.set('templateData.insideGroup', true);
}
}
});
Discourse.View.reopenClass({
/**
Register a view helper for ease of use
@method registerHelper
@param {String} helperName the name of the helper
@param {Ember.View} helperClass the view that will be inserted by the helper
**/
registerHelper: function(helperName, helperClass) {
Ember.Handlebars.registerHelper(helperName, function(options) {
var hash = options.hash,
types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, helperClass, options);
});
},
renderIfChanged: function() {
Em.warn("`rerenderIfChanged` is deprecated. Use the `StringBuffer` mixin with `rerenderTriggers` instead.");
var args = Array.prototype.slice.call(arguments, 0);
args.unshift(function () {
Ember.run.once(this, 'rerender');
});
return Ember.observer.apply(this, args);
}
});

View File

@ -0,0 +1,17 @@
import Presence from 'discourse/mixins/presence';
const View = Ember.View.extend(Presence, {});
View.reopenClass({
registerHelper(helperName, helperClass) {
Ember.Handlebars.registerHelper(helperName, function(options) {
var hash = options.hash,
types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, helperClass, options);
});
}
});
export default View;

View File

@ -24,6 +24,7 @@
//= require ./discourse/lib/avatar-template //= require ./discourse/lib/avatar-template
//= require ./discourse/lib/safari-hacks //= require ./discourse/lib/safari-hacks
//= require_tree ./discourse/adapters //= require_tree ./discourse/adapters
//= require ./discourse/models/rest
//= require ./discourse/models/model //= require ./discourse/models/model
//= require ./discourse/models/post //= require ./discourse/models/post
//= require ./discourse/models/user_action //= require ./discourse/models/user_action
@ -36,6 +37,7 @@
//= require ./discourse/controllers/object //= require ./discourse/controllers/object
//= require ./discourse/controllers/navigation/default //= require ./discourse/controllers/navigation/default
//= require ./discourse/views/view //= require ./discourse/views/view
//= require ./discourse/views/grouped
//= require ./discourse/views/container //= require ./discourse/views/container
//= require ./discourse/views/modal-body //= require ./discourse/views/modal-body
//= require ./discourse/views/flag //= require ./discourse/views/flag

View File

@ -107,6 +107,7 @@ module Tilt
# HAX # HAX
result = "Controller" if result == "ControllerController" result = "Controller" if result == "ControllerController"
result = "Route" if result == "DiscourseRoute" result = "Route" if result == "DiscourseRoute"
result = "View" if result == "ViewView"
result.gsub!(/Mixin$/, '') result.gsub!(/Mixin$/, '')
result.gsub!(/Model$/, '') result.gsub!(/Model$/, '')

View File

@ -1,5 +0,0 @@
moduleFor("controller:admin-email-index");
test("mixes in Discourse.Presence", function() {
ok(Discourse.Presence.detect(this.subject()));
});

View File

@ -1,5 +0,0 @@
moduleFor("controller:admin-email-preview-digest");
test("mixes in Discourse.Presence", function() {
ok(Discourse.Presence.detect(this.subject()));
});

View File

@ -1,7 +1,8 @@
import DiscourseController from 'discourse/controllers/controller'; import DiscourseController from 'discourse/controllers/controller';
import Presence from 'discourse/mixins/presence';
module("DiscourseController"); module("DiscourseController");
test("includes mixins", function() { test("includes mixins", function() {
ok(Discourse.Presence.detect(DiscourseController.create()), "Discourse.Presence"); ok(Presence.detect(DiscourseController.create()), "has Presence");
}); });

View File

@ -131,7 +131,7 @@ export default function() {
return response(200, { basic_topic: {id: request.params.id, return response(200, { basic_topic: {id: request.params.id,
title: data.title, title: data.title,
fancy_title: data.title, fancy_title: data.title,
slug: request.params.slug } }) slug: request.params.slug } });
}); });
this.post('/posts', function(request) { this.post('/posts', function(request) {

View File

@ -1,6 +1,8 @@
module("Discourse.Presence"); import Presence from 'discourse/mixins/presence';
var testObj = Em.Object.createWithMixins(Discourse.Presence, { module("mixin:presence");
var testObj = Em.Object.createWithMixins(Presence, {
emptyString: "", emptyString: "",
nonEmptyString: "Evil Trout", nonEmptyString: "Evil Trout",
emptyArray: [], emptyArray: [],

View File

@ -1,14 +1,17 @@
import Presence from 'discourse/mixins/presence';
import Model from 'discourse/models/model';
module("Discourse.Model"); module("Discourse.Model");
test("mixes in Discourse.Presence", function() { test("mixes in Presence", function() {
ok(Discourse.Presence.detect(Discourse.Model.create())); ok(Presence.detect(Model.create()));
}); });
test("extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids", function() { test("extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids", function() {
var firstObject = {id: "id_1", foo: "foo_1"}; var firstObject = {id: "id_1", foo: "foo_1"};
var secondObject = {id: "id_2", foo: "foo_2"}; var secondObject = {id: "id_2", foo: "foo_2"};
var actual = Discourse.Model.extractByKey([firstObject, secondObject], Ember.Object); var actual = Model.extractByKey([firstObject, secondObject], Ember.Object);
var expected = { var expected = {
id_1: Ember.Object.create(firstObject), id_1: Ember.Object.create(firstObject),
id_2: Ember.Object.create(secondObject) id_2: Ember.Object.create(secondObject)
@ -18,6 +21,6 @@ test("extractByKey: converts a list of hashes into a hash of instances of specif
}); });
test("extractByKey: returns an empty hash if there isn't anything to convert", function() { test("extractByKey: returns an empty hash if there isn't anything to convert", function() {
deepEqual(Discourse.Model.extractByKey(), {}, "when called without parameters"); deepEqual(Model.extractByKey(), {}, "when called without parameters");
deepEqual(Discourse.Model.extractByKey([]), {}, "when called with an empty array"); deepEqual(Model.extractByKey([]), {}, "when called with an empty array");
}); });

View File

@ -1,3 +1,5 @@
import Presence from 'discourse/mixins/presence';
var SomeViewClass = Ember.View.extend(); var SomeViewClass = Ember.View.extend();
function containerHasOnlyOneChild(containerView, klass) { function containerHasOnlyOneChild(containerView, klass) {
@ -17,9 +19,9 @@ function childHasProperty(containerView, name) {
moduleFor("view:container"); moduleFor("view:container");
test("mixes in Discourse.Presence", function() { test("mixes in Presence", function() {
var containerView = this.subject(); var containerView = this.subject();
ok(Discourse.Presence.detect(containerView)); ok(Presence.detect(containerView));
}); });
test("attachViewWithArgs: creates a view of a given class with given properties and appends it to the container", function() { test("attachViewWithArgs: creates a view of a given class with given properties and appends it to the container", function() {

View File

@ -1,3 +1,5 @@
import Presence from 'discourse/mixins/presence';
var oldHelpers; var oldHelpers;
module("Discourse.View", { module("Discourse.View", {
@ -10,8 +12,8 @@ module("Discourse.View", {
} }
}); });
test("mixes in Discourse.Presence", function() { test("mixes in Presence", function() {
ok(Discourse.Presence.detect(Discourse.View.create())); ok(Presence.detect(Discourse.View.create()));
}); });
test("registerHelper: enables embedding a child view in a parent view via dedicated, named helper instead of generic 'view' helper", function() { test("registerHelper: enables embedding a child view in a parent view via dedicated, named helper instead of generic 'view' helper", function() {