-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: emberjs/rfcs#756 Update: emberjs/rfcs#788 Guides: ember-learn/guides-source#1924 * Convert truth-helpers to use plain functions Mainly to test that the polyfill is working, but it's a good refactor anyway.
- Loading branch information
1 parent
7958f57
commit 0fa9252
Showing
12 changed files
with
44 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 2 additions & 6 deletions
8
app/assets/javascripts/truth-helpers/addon/helpers/includes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters