mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
DEV: Remove ember-addons (#9559)
We weren't using this very much and introduces a dependency between discourse-common and discourse which makes moving to yarn workspaces more difficult. In the future we might user ember-addons properly but for now it's easier to move the code into discourse-common. Note the old folder is still there because at least one plugin was still requiring the old files. It will be removed in the future.
This commit is contained in:
parent
84be92c067
commit
c1cc2f2a05
17 changed files with 167 additions and 175 deletions
|
@ -26,9 +26,6 @@ acc5cbdf8ecb9293a0fa9474ee73baf499c02428
|
||||||
# Rename discourse-common es6 -> js
|
# Rename discourse-common es6 -> js
|
||||||
167503ca4824e37a2e93d74b3f50271556d0ba8e
|
167503ca4824e37a2e93d74b3f50271556d0ba8e
|
||||||
|
|
||||||
# Rename ember-addons es6 -> js
|
|
||||||
16ba50bce362c1eefe1881f86c67bec66f493abb
|
|
||||||
|
|
||||||
# Rename some root files
|
# Rename some root files
|
||||||
11938d58d4b1bea1ff43306450da7b24f05db0a
|
11938d58d4b1bea1ff43306450da7b24f05db0a
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
//= require_tree ./ember-addons/utils
|
|
||||||
//= require_tree ./discourse-common
|
//= require_tree ./discourse-common
|
||||||
//= require ./ember-addons/decorator-alias
|
|
||||||
//= require ./ember-addons/macro-alias
|
|
||||||
//= require ./ember-addons/fmt
|
|
||||||
//= require ./polyfills
|
//= require ./polyfills
|
||||||
//= require_tree ./select-kit
|
//= require_tree ./select-kit
|
||||||
//= require ./discourse/app/app
|
//= require ./discourse/app/app
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
import extractValue from "discourse-common/utils/extract-value";
|
||||||
|
|
||||||
|
export default function decoratorAlias(fn, errorMessage) {
|
||||||
|
return function(...params) {
|
||||||
|
// determine if user called as @discourseComputed('blah', 'blah') or @discourseComputed
|
||||||
|
if (params.length === 0) {
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
} else {
|
||||||
|
return function(target, key, desc) {
|
||||||
|
return {
|
||||||
|
enumerable: desc.enumerable,
|
||||||
|
configurable: desc.configurable,
|
||||||
|
writable: desc.writable,
|
||||||
|
initializer: function() {
|
||||||
|
var value = extractValue(desc);
|
||||||
|
return fn.apply(null, params.concat(value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
import handleDescriptor from "ember-addons/utils/handle-descriptor";
|
import handleDescriptor from "discourse-common/utils/handle-descriptor";
|
||||||
import isDescriptor from "ember-addons/utils/is-descriptor";
|
import isDescriptor from "discourse-common/utils/is-descriptor";
|
||||||
import extractValue from "ember-addons/utils/extract-value";
|
import extractValue from "discourse-common/utils/extract-value";
|
||||||
|
import decoratorAlias from "discourse-common/utils/decorator-alias";
|
||||||
|
import macroAlias from "discourse-common/utils/macro-alias";
|
||||||
import { schedule, next } from "@ember/runloop";
|
import { schedule, next } from "@ember/runloop";
|
||||||
|
|
||||||
export default function discourseComputedDecorator(...params) {
|
export default function discourseComputedDecorator(...params) {
|
||||||
|
@ -39,8 +41,6 @@ export function readOnly(target, name, desc) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
import decoratorAlias from "ember-addons/decorator-alias";
|
|
||||||
|
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
export var on = decoratorAlias(Ember.on, "Can not `on` without event names");
|
export var on = decoratorAlias(Ember.on, "Can not `on` without event names");
|
||||||
export var observes = decoratorAlias(
|
export var observes = decoratorAlias(
|
||||||
|
@ -48,8 +48,6 @@ export var observes = decoratorAlias(
|
||||||
"Can not `observe` without property names"
|
"Can not `observe` without property names"
|
||||||
);
|
);
|
||||||
|
|
||||||
import macroAlias from "ember-addons/macro-alias";
|
|
||||||
|
|
||||||
export var alias = macroAlias(Ember.computed.alias);
|
export var alias = macroAlias(Ember.computed.alias);
|
||||||
export var and = macroAlias(Ember.computed.and);
|
export var and = macroAlias(Ember.computed.and);
|
||||||
export var bool = macroAlias(Ember.computed.bool);
|
export var bool = macroAlias(Ember.computed.bool);
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
export default function extractValue(desc) {
|
||||||
|
return (
|
||||||
|
desc.value || (typeof desc.initializer === "function" && desc.initializer())
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
import { computed, get } from "@ember/object";
|
||||||
|
import extractValue from "./extract-value";
|
||||||
|
|
||||||
|
export default function handleDescriptor(target, key, desc, params = []) {
|
||||||
|
return {
|
||||||
|
enumerable: desc.enumerable,
|
||||||
|
configurable: desc.configurable,
|
||||||
|
writeable: desc.writeable,
|
||||||
|
initializer: function() {
|
||||||
|
let computedDescriptor;
|
||||||
|
|
||||||
|
if (desc.writable) {
|
||||||
|
var val = extractValue(desc);
|
||||||
|
if (typeof val === "object") {
|
||||||
|
let value = {};
|
||||||
|
if (val.get) {
|
||||||
|
value.get = callUserSuppliedGet(params, val.get);
|
||||||
|
}
|
||||||
|
if (val.set) {
|
||||||
|
value.set = callUserSuppliedSet(params, val.set);
|
||||||
|
}
|
||||||
|
computedDescriptor = value;
|
||||||
|
} else {
|
||||||
|
computedDescriptor = callUserSuppliedGet(params, val);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
"ember-computed-decorators does not support using getters and setters"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return computed.apply(null, params.concat(computedDescriptor));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function niceAttr(attr) {
|
||||||
|
const parts = attr.split(".");
|
||||||
|
let i;
|
||||||
|
|
||||||
|
for (i = 0; i < parts.length; i++) {
|
||||||
|
if (
|
||||||
|
parts[i] === "@each" ||
|
||||||
|
parts[i] === "[]" ||
|
||||||
|
parts[i].indexOf("{") !== -1
|
||||||
|
) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.slice(0, i).join(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
function callUserSuppliedGet(params, func) {
|
||||||
|
params = params.map(niceAttr);
|
||||||
|
return function() {
|
||||||
|
let paramValues = params.map(p => get(this, p));
|
||||||
|
|
||||||
|
return func.apply(this, paramValues);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function callUserSuppliedSet(params, func) {
|
||||||
|
params = params.map(niceAttr);
|
||||||
|
return function(key, value) {
|
||||||
|
let paramValues = params.map(p => get(this, p));
|
||||||
|
paramValues.unshift(value);
|
||||||
|
|
||||||
|
return func.apply(this, paramValues);
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
export default function isDescriptor(item) {
|
||||||
|
return (
|
||||||
|
item &&
|
||||||
|
typeof item === "object" &&
|
||||||
|
"writable" in item &&
|
||||||
|
"enumerable" in item &&
|
||||||
|
"configurable" in item
|
||||||
|
);
|
||||||
|
}
|
24
app/assets/javascripts/discourse-common/utils/macro-alias.js
Normal file
24
app/assets/javascripts/discourse-common/utils/macro-alias.js
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import isDescriptor from "discourse-common/utils/is-descriptor";
|
||||||
|
|
||||||
|
function handleDescriptor(target, property, desc, fn, params = []) {
|
||||||
|
return {
|
||||||
|
enumerable: desc.enumerable,
|
||||||
|
configurable: desc.configurable,
|
||||||
|
writable: desc.writable,
|
||||||
|
initializer: function() {
|
||||||
|
return fn(...params);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function macroAlias(fn) {
|
||||||
|
return function(...params) {
|
||||||
|
if (isDescriptor(params[params.length - 1])) {
|
||||||
|
return handleDescriptor(...params, fn);
|
||||||
|
} else {
|
||||||
|
return function(target, property, desc) {
|
||||||
|
return handleDescriptor(target, property, desc, fn, params);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,7 +1,31 @@
|
||||||
import { computed } from "@ember/object";
|
import { computed } from "@ember/object";
|
||||||
import addonFmt from "ember-addons/fmt";
|
|
||||||
import { htmlSafe as htmlSafeTemplateHelper } from "@ember/template";
|
import { htmlSafe as htmlSafeTemplateHelper } from "@ember/template";
|
||||||
|
|
||||||
|
function addonFmt(str, formats) {
|
||||||
|
let cachedFormats = formats;
|
||||||
|
|
||||||
|
if (!_.isArray(cachedFormats) || arguments.length > 2) {
|
||||||
|
cachedFormats = new Array(arguments.length - 1);
|
||||||
|
|
||||||
|
for (let i = 1, l = arguments.length; i < l; i++) {
|
||||||
|
cachedFormats[i - 1] = arguments[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// first, replace any ORDERED replacements.
|
||||||
|
let idx = 0; // the current index for non-numerical replacements
|
||||||
|
return str.replace(/%@([0-9]+)?/g, function(s, argIndex) {
|
||||||
|
argIndex = argIndex ? parseInt(argIndex, 10) - 1 : idx++;
|
||||||
|
s = cachedFormats[argIndex];
|
||||||
|
return typeof s === "string"
|
||||||
|
? s
|
||||||
|
: s === null
|
||||||
|
? "(null)"
|
||||||
|
: s === undefined
|
||||||
|
? ""
|
||||||
|
: "" + s;
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
Returns whether two properties are equal to each other.
|
Returns whether two properties are equal to each other.
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1 @@
|
||||||
import extractValue from "./utils/extract-value";
|
// left empty for backwards compatibility. Should be removed in the future
|
||||||
|
|
||||||
export default function decoratorAlias(fn, errorMessage) {
|
|
||||||
return function(...params) {
|
|
||||||
// determine if user called as @discourseComputed('blah', 'blah') or @discourseComputed
|
|
||||||
if (params.length === 0) {
|
|
||||||
throw new Error(errorMessage);
|
|
||||||
} else {
|
|
||||||
return function(target, key, desc) {
|
|
||||||
return {
|
|
||||||
enumerable: desc.enumerable,
|
|
||||||
configurable: desc.configurable,
|
|
||||||
writable: desc.writable,
|
|
||||||
initializer: function() {
|
|
||||||
var value = extractValue(desc);
|
|
||||||
return fn.apply(null, params.concat(value));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,25 +1 @@
|
||||||
export default function(str, formats) {
|
// left empty for backwards compatibility. Should be removed in the future
|
||||||
let cachedFormats = formats;
|
|
||||||
|
|
||||||
if (!_.isArray(cachedFormats) || arguments.length > 2) {
|
|
||||||
cachedFormats = new Array(arguments.length - 1);
|
|
||||||
|
|
||||||
for (let i = 1, l = arguments.length; i < l; i++) {
|
|
||||||
cachedFormats[i - 1] = arguments[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// first, replace any ORDERED replacements.
|
|
||||||
let idx = 0; // the current index for non-numerical replacements
|
|
||||||
return str.replace(/%@([0-9]+)?/g, function(s, argIndex) {
|
|
||||||
argIndex = argIndex ? parseInt(argIndex, 10) - 1 : idx++;
|
|
||||||
s = cachedFormats[argIndex];
|
|
||||||
return typeof s === "string"
|
|
||||||
? s
|
|
||||||
: s === null
|
|
||||||
? "(null)"
|
|
||||||
: s === undefined
|
|
||||||
? ""
|
|
||||||
: "" + s;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,24 +1 @@
|
||||||
import isDescriptor from "./utils/is-descriptor";
|
// left empty for backwards compatibility. Should be removed in the future
|
||||||
|
|
||||||
function handleDescriptor(target, property, desc, fn, params = []) {
|
|
||||||
return {
|
|
||||||
enumerable: desc.enumerable,
|
|
||||||
configurable: desc.configurable,
|
|
||||||
writable: desc.writable,
|
|
||||||
initializer: function() {
|
|
||||||
return fn(...params);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function macroAlias(fn) {
|
|
||||||
return function(...params) {
|
|
||||||
if (isDescriptor(params[params.length - 1])) {
|
|
||||||
return handleDescriptor(...params, fn);
|
|
||||||
} else {
|
|
||||||
return function(target, property, desc) {
|
|
||||||
return handleDescriptor(target, property, desc, fn, params);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1 @@
|
||||||
export default function extractValue(desc) {
|
// left for backwards compatibility. remove in the future.
|
||||||
return (
|
|
||||||
desc.value || (typeof desc.initializer === "function" && desc.initializer())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,71 +1 @@
|
||||||
import { computed, get } from "@ember/object";
|
// left for backwards compatibility. remove in the future.
|
||||||
import extractValue from "./extract-value";
|
|
||||||
|
|
||||||
export default function handleDescriptor(target, key, desc, params = []) {
|
|
||||||
return {
|
|
||||||
enumerable: desc.enumerable,
|
|
||||||
configurable: desc.configurable,
|
|
||||||
writeable: desc.writeable,
|
|
||||||
initializer: function() {
|
|
||||||
let computedDescriptor;
|
|
||||||
|
|
||||||
if (desc.writable) {
|
|
||||||
var val = extractValue(desc);
|
|
||||||
if (typeof val === "object") {
|
|
||||||
let value = {};
|
|
||||||
if (val.get) {
|
|
||||||
value.get = callUserSuppliedGet(params, val.get);
|
|
||||||
}
|
|
||||||
if (val.set) {
|
|
||||||
value.set = callUserSuppliedSet(params, val.set);
|
|
||||||
}
|
|
||||||
computedDescriptor = value;
|
|
||||||
} else {
|
|
||||||
computedDescriptor = callUserSuppliedGet(params, val);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Error(
|
|
||||||
"ember-computed-decorators does not support using getters and setters"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return computed.apply(null, params.concat(computedDescriptor));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function niceAttr(attr) {
|
|
||||||
const parts = attr.split(".");
|
|
||||||
let i;
|
|
||||||
|
|
||||||
for (i = 0; i < parts.length; i++) {
|
|
||||||
if (
|
|
||||||
parts[i] === "@each" ||
|
|
||||||
parts[i] === "[]" ||
|
|
||||||
parts[i].indexOf("{") !== -1
|
|
||||||
) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return parts.slice(0, i).join(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
function callUserSuppliedGet(params, func) {
|
|
||||||
params = params.map(niceAttr);
|
|
||||||
return function() {
|
|
||||||
let paramValues = params.map(p => get(this, p));
|
|
||||||
|
|
||||||
return func.apply(this, paramValues);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function callUserSuppliedSet(params, func) {
|
|
||||||
params = params.map(niceAttr);
|
|
||||||
return function(key, value) {
|
|
||||||
let paramValues = params.map(p => get(this, p));
|
|
||||||
paramValues.unshift(value);
|
|
||||||
|
|
||||||
return func.apply(this, paramValues);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +1 @@
|
||||||
export default function isDescriptor(item) {
|
// left for backwards compatibility. remove in the future.
|
||||||
return (
|
|
||||||
item &&
|
|
||||||
typeof item === "object" &&
|
|
||||||
"writable" in item &&
|
|
||||||
"enumerable" in item &&
|
|
||||||
"configurable" in item
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
//= require_tree ./ember-addons
|
|
||||||
//= require admin/models/user-field
|
//= require admin/models/user-field
|
||||||
//= require admin/models/site-setting
|
//= require admin/models/site-setting
|
||||||
//= require admin/models/screened-ip-address
|
//= require admin/models/screened-ip-address
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
//= require_tree ./ember-addons/utils
|
|
||||||
//= require ./ember-addons/decorator-alias
|
|
||||||
//= require ./ember-addons/macro-alias
|
|
||||||
//= require ./discourse-common/utils/decorators
|
//= require ./discourse-common/utils/decorators
|
||||||
//= require_tree ./discourse-common
|
//= require_tree ./discourse-common
|
||||||
//= require i18n-patches
|
//= require i18n-patches
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue