-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit updates the argument handling: * To match [RFC PR #620](emberjs/rfcs#620) * Returns `null` on `null` or `undefined` * Use development mode assertions for other invalid arguments * Add test for modifiers usage * Add test for `...attributes` usage * To match more closely the likely Ember side implementation * Handle argument errors at runtime * `owner.hasRegistration('helper:element') === true` Since the argument errors are moved to runtime, this also removes the need for separate node tests. Previously, that also caused an error when `ember-auto-import` is included. Since we removed the `qunit` dependency we can now include `ember-auto-import` to align with the default addon blueprint. See also https://discordapp.com/channels/480462759797063690/485447409296736276/704799818316251216 Closes #6
- Loading branch information
1 parent
d2bd64c
commit 91a6edf
Showing
13 changed files
with
2,351 additions
and
265 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
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,36 +1,48 @@ | ||
import Helper from '@ember/component/helper'; | ||
import { assert, runInDebug } from '@ember/debug'; | ||
|
||
function UNINITIALIZED() {} | ||
|
||
export default Helper.extend({ | ||
init() { | ||
this._super(...arguments); | ||
this.tagName = UNINITIALIZED; | ||
this.componentName = UNINITIALIZED; | ||
this.componentName = null; | ||
}, | ||
|
||
compute([tagName]) { | ||
if (tagName === this.tagName) { | ||
return this.componentName; | ||
} else if (typeof tagName !== 'string') { | ||
let message = 'the argument passed to the `element` helper must be a string'; | ||
compute(params, hash) { | ||
assert('The `element` helper takes a single positional argument', params.length === 1); | ||
assert('The `element` helper does not take any named arguments', Object.keys(hash).length === 0); | ||
|
||
try { | ||
message += ` (you passed \`${tagName}\`)`; | ||
} catch (e) { | ||
// ignore | ||
} | ||
let tagName = params[0]; | ||
|
||
throw new Error(message); | ||
} else { | ||
if (tagName !== this.tagName) { | ||
this.tagName = tagName; | ||
|
||
// return a different component name to force a teardown | ||
if (this.componentName === '-dynamic-element') { | ||
return this.componentName = '-dynamic-element-alt'; | ||
if (typeof tagName === 'string') { | ||
// return a different component name to force a teardown | ||
if (this.componentName === '-dynamic-element') { | ||
this.componentName = '-dynamic-element-alt'; | ||
} else { | ||
this.componentName = '-dynamic-element'; | ||
} | ||
} else { | ||
return this.componentName = '-dynamic-element'; | ||
this.componentName = null; | ||
|
||
runInDebug(() => { | ||
let message = 'The argument passed to the `element` helper must be a string'; | ||
|
||
try { | ||
message += ` (you passed \`${tagName}\`)`; | ||
} catch (e) { | ||
// ignore | ||
} | ||
|
||
assert(message, tagName === undefined || tagName === null); | ||
}); | ||
} | ||
} | ||
|
||
return this.componentName; | ||
} | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import { assert } from '@ember/debug'; | ||
|
||
export default helper(function() { | ||
// This helper (`element`, as opposed to `-element`) mostly exists to satisfy | ||
// things like `owner.hasRegistration('helper:element')`. The AST transform | ||
// replaces all usages of `(element ...)` into `(component (-element ...))` | ||
// so if this helper is invoked directly, something is wrong. | ||
|
||
assert( | ||
'The `element` helper polyfill encounted an unexpected error. ' + | ||
'Please report the issue at http://github.com/tildeio/ember-element-helper ' + | ||
'with the usage and conditions that caused this error.' | ||
); | ||
|
||
return null; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-element-helper/helpers/element'; |
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 was deleted.
Oops, something went wrong.
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 +1 @@ | ||
<@tag id="content">{{yield}}</@tag> | ||
<@tag id="content" ...attributes>{{yield}}</@tag> |
Oops, something went wrong.