From c00f5f5704de4994da4ff2d88a8bdcfb9780a700 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Fri, 28 Aug 2020 14:57:36 -0400 Subject: [PATCH 1/3] Remove path assertion to better align with `mut` `mut` was able to handle `undefined` values. This was very helpful for things like testing, where you may only want to define a few values, not everything for your whole app. --- addon/helpers/set.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/addon/helpers/set.js b/addon/helpers/set.js index 06911d0..1ea0033 100644 --- a/addon/helpers/set.js +++ b/addon/helpers/set.js @@ -1,5 +1,4 @@ import { helper } from '@ember/component/helper'; -import { assert } from '@ember/debug'; import { set as emberSet } from '@ember/object'; function set(positional, named) { @@ -15,14 +14,11 @@ function set(positional, named) { path = maybePath; } - assert( - 'you must pass a path to {{set}}. You can pass a path statically, as in `{{set this.foo}}`, or with the path argument dynamically, as in `{{set this path="foo"}}`', - Boolean(target) && (typeof path === 'string' && path.length > 0 || typeof path === 'symbol' || typeof path === 'number') - ); - - return positional.length === 3 - ? () => emberSet(target, path, maybeValue) - : value => emberSet(target, path, value); + if (path) { + return positional.length === 3 + ? () => emberSet(target, path, maybeValue) + : value => emberSet(target, path, value); + } } export default helper(set); From 471770b987409ff290fbd23ea9f444c47c7b8971 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Fri, 28 Aug 2020 15:09:51 -0400 Subject: [PATCH 2/3] Update set.js --- addon/helpers/set.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/addon/helpers/set.js b/addon/helpers/set.js index 1ea0033..eab40a6 100644 --- a/addon/helpers/set.js +++ b/addon/helpers/set.js @@ -1,4 +1,5 @@ import { helper } from '@ember/component/helper'; +import { assert } from '@ember/debug'; import { set as emberSet } from '@ember/object'; function set(positional, named) { @@ -14,11 +15,14 @@ function set(positional, named) { path = maybePath; } - if (path) { - return positional.length === 3 - ? () => emberSet(target, path, maybeValue) - : value => emberSet(target, path, value); - } + assert( + 'you must pass a path to {{set}}. You can pass a path statically, as in `{{set this.foo}}`, or with the path argument dynamically, as in `{{set this path="foo"}}`', + typeof path === 'string' && path.length > 0 || typeof path === 'symbol' || typeof path === 'number') + ); + + return positional.length === 3 + ? () => emberSet(target, path, maybeValue) + : value => emberSet(target, path, value); } export default helper(set); From 5143db6613992f1299b8918f9d3819d0c15f2af3 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Fri, 28 Aug 2020 15:10:59 -0400 Subject: [PATCH 3/3] Update set.js --- addon/helpers/set.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/helpers/set.js b/addon/helpers/set.js index eab40a6..cfd3f8c 100644 --- a/addon/helpers/set.js +++ b/addon/helpers/set.js @@ -17,7 +17,7 @@ function set(positional, named) { assert( 'you must pass a path to {{set}}. You can pass a path statically, as in `{{set this.foo}}`, or with the path argument dynamically, as in `{{set this path="foo"}}`', - typeof path === 'string' && path.length > 0 || typeof path === 'symbol' || typeof path === 'number') + (typeof path === 'string' && path.length > 0 || typeof path === 'symbol' || typeof path === 'number') ); return positional.length === 3