mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
DEV: enable plain functions as helpers in Ember (#22023)
* Enable "plain function as helpers" polyfill This feature landed in Ember 4.5+, but this polyfill would allow it to work on 3.25+ References RFC: https://github.com/emberjs/rfcs/pull/756 Update: https://github.com/emberjs/rfcs/pull/788 Guides: https://github.com/ember-learn/guides-source/pull/1924 * Convert truth-helpers to use plain functions Mainly to test that the polyfill is working, but it's a good refactor anyway.
This commit is contained in:
parent
7958f57174
commit
0fa92529ed
@ -100,6 +100,7 @@
|
||||
"ember-cli-progress-ci": "1.0.0",
|
||||
"ember-cli-sri": "^2.1.1",
|
||||
"ember-cli-terser": "^4.0.2",
|
||||
"ember-functions-as-helper-polyfill": "^2.1.1",
|
||||
"ember-qunit": "^6.2.0",
|
||||
"ember-exam": "^8.0.0",
|
||||
"eslint": "^8.42.0",
|
||||
|
@ -1,13 +1,13 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
import truthConvert from "../utils/truth-convert";
|
||||
|
||||
export function and(params) {
|
||||
for (let i = 0, len = params.length; i < len; i++) {
|
||||
if (truthConvert(params[i]) === false) {
|
||||
return params[i];
|
||||
export default function and(...args) {
|
||||
let arg = false;
|
||||
|
||||
for (arg of args) {
|
||||
if (truthConvert(arg) === false) {
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
return params[params.length - 1];
|
||||
}
|
||||
|
||||
export default Helper.helper(and);
|
||||
return arg;
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
|
||||
export function eq(params) {
|
||||
return params[0] === params[1];
|
||||
export default function eq(left, right) {
|
||||
return left === right;
|
||||
}
|
||||
|
||||
export default Helper.helper(eq);
|
||||
|
@ -1,7 +1,5 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
|
||||
export function gt([left, right], hash) {
|
||||
if (hash.forceNumber) {
|
||||
export default function gt(left, right, { forceNumber = false } = {}) {
|
||||
if (forceNumber) {
|
||||
if (typeof left !== "number") {
|
||||
left = Number(left);
|
||||
}
|
||||
@ -11,5 +9,3 @@ export function gt([left, right], hash) {
|
||||
}
|
||||
return left > right;
|
||||
}
|
||||
|
||||
export default Helper.helper(gt);
|
||||
|
@ -1,7 +1,5 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
|
||||
export function gte([left, right], hash) {
|
||||
if (hash.forceNumber) {
|
||||
export default function gte(left, right, { forceNumber = false } = {}) {
|
||||
if (forceNumber) {
|
||||
if (typeof left !== "number") {
|
||||
left = Number(left);
|
||||
}
|
||||
@ -11,5 +9,3 @@ export function gte([left, right], hash) {
|
||||
}
|
||||
return left >= right;
|
||||
}
|
||||
|
||||
export default Helper.helper(gte);
|
||||
|
@ -1,7 +1,3 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
|
||||
export function includes(params) {
|
||||
return params[0].includes(params[1]);
|
||||
export default function includes(array, item) {
|
||||
return array.includes(item);
|
||||
}
|
||||
|
||||
export default Helper.helper(includes);
|
||||
|
@ -1,7 +1,5 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
|
||||
export function lt([left, right], hash) {
|
||||
if (hash.forceNumber) {
|
||||
export default function lt(left, right, { forceNumber = false } = {}) {
|
||||
if (forceNumber) {
|
||||
if (typeof left !== "number") {
|
||||
left = Number(left);
|
||||
}
|
||||
@ -11,5 +9,3 @@ export function lt([left, right], hash) {
|
||||
}
|
||||
return left < right;
|
||||
}
|
||||
|
||||
export default Helper.helper(lt);
|
||||
|
@ -1,7 +1,5 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
|
||||
export function lte([left, right], hash) {
|
||||
if (hash.forceNumber) {
|
||||
export default function lte(left, right, { forceNumber = false } = {}) {
|
||||
if (forceNumber) {
|
||||
if (typeof left !== "number") {
|
||||
left = Number(left);
|
||||
}
|
||||
@ -11,5 +9,3 @@ export function lte([left, right], hash) {
|
||||
}
|
||||
return left <= right;
|
||||
}
|
||||
|
||||
export default Helper.helper(lte);
|
||||
|
@ -1,7 +1,3 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
|
||||
export function notEqualHelper(params) {
|
||||
return params[0] !== params[1];
|
||||
export default function notEq(left, right) {
|
||||
return left !== right;
|
||||
}
|
||||
|
||||
export default Helper.helper(notEqualHelper);
|
||||
|
@ -1,13 +1,11 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
import truthConvert from "../utils/truth-convert";
|
||||
|
||||
export function not(params) {
|
||||
for (let i = 0, len = params.length; i < len; i++) {
|
||||
if (truthConvert(params[i]) === true) {
|
||||
export default function not(...args) {
|
||||
for (let arg of args) {
|
||||
if (truthConvert(arg) === true) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export default Helper.helper(not);
|
||||
|
@ -1,13 +1,13 @@
|
||||
import Helper from "@ember/component/helper";
|
||||
import truthConvert from "../utils/truth-convert";
|
||||
|
||||
export function or(params) {
|
||||
for (let i = 0, len = params.length; i < len; i++) {
|
||||
if (truthConvert(params[i]) === true) {
|
||||
return params[i];
|
||||
export default function or(...args) {
|
||||
let arg = false;
|
||||
|
||||
for (arg of args) {
|
||||
if (truthConvert(arg) === true) {
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
return params[params.length - 1];
|
||||
}
|
||||
|
||||
export default Helper.helper(or);
|
||||
return arg;
|
||||
}
|
||||
|
@ -4284,6 +4284,15 @@ ember-export-application-global@^2.0.1:
|
||||
resolved "https://registry.yarnpkg.com/ember-export-application-global/-/ember-export-application-global-2.0.1.tgz#b120a70e322ab208defc9e2daebe8d0dfc2dcd46"
|
||||
integrity sha512-B7wiurPgsxsSGzJuPFkpBWnaeuCu2PGpG2BjyrfA1VcL7//o+5RSnZqiCEY326y7qmxb2GoCgo0ft03KBU0rRw==
|
||||
|
||||
ember-functions-as-helper-polyfill@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/ember-functions-as-helper-polyfill/-/ember-functions-as-helper-polyfill-2.1.1.tgz#25240db29b4cd0366a2d2954d2ea26ce0872ff8f"
|
||||
integrity sha512-vZ2w9G/foohwtPm99Jos1m6bhlXyyyiJ4vhLbxyjWB4wh7bcpRzXPgCewDRrwefZQ2BwtHg3c9zvVMlI0g+o2Q==
|
||||
dependencies:
|
||||
ember-cli-babel "^7.26.11"
|
||||
ember-cli-typescript "^5.0.0"
|
||||
ember-cli-version-checker "^5.1.2"
|
||||
|
||||
ember-load-initializers@^2.1.1:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/ember-load-initializers/-/ember-load-initializers-2.1.2.tgz#8a47a656c1f64f9b10cecdb4e22a9d52ad9c7efa"
|
||||
|
Loading…
Reference in New Issue
Block a user