-
Notifications
You must be signed in to change notification settings - Fork 12
Deprecate the {{data}} helper in favor of {{domData}} #500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
@param {String} [key] The name of the data attribute to use for the value. | ||
@param {can-stache/expressions/key-lookup|can-stache/expressions/call} [value] | ||
The value to associate with the key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not 100% sure I got these docs right. Suggestions welcome.
> **Note:** this contrived example is just to demonstrate the `{{domData}}` | ||
> helper; if you need to create a click handler, you should write | ||
> `<li on:click="handler(this)">` and add a `handler()` method to your | ||
> view-model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this distracting or useful? Maybe I could include a better example that wouldn’t need this disclaimer?
var dataHelper = function(attr) { | ||
// options will either be the second or third argument. | ||
// Get the argument before that. | ||
var data = arguments.length === 2 ? this : arguments[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, this never worked in 4.x
span; | ||
|
||
div = doc.createElement('div'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a copy of the {{data}} tests, so in 5.x we can just drop the {{data}} tests in favor for these new {{domData}} tests.
c8f9568
to
1b57db6
Compare
helpers/core.js
Outdated
return function(el){ | ||
domData.set.call( el, attr, data || this.context ); | ||
dev.warn('The {{data}} helper has been deprecated; use {{domData}} instead: https://canjs.com/doc/can-stache.helpers.domData.html'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably be wrapped in //!steal-remove-start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed.
helpers/core.js
Outdated
|
||
var domDataHelper = function(attr, optionalValue) { | ||
var data = optionalValue || this; | ||
return function(el) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
give this function a name.
return function setDomData( el ) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, is this the best way currently of getting a reference to the element? It might be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave both setter functions a name. I’m not sure if there’s a better way to get a reference to the element.
helpers/core.js
Outdated
var domDataHelper = function(attr, optionalValue) { | ||
var data = optionalValue || this; | ||
return function(el) { | ||
domData.set.call( el, attr, data && data.context || data ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would data.context
be? That seems like a mistake. What if I passed an object with a .context
property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the test that passed when data.context
is checked:
can-stache/test/stache-test.js
Lines 1998 to 1999 in f47cdfa
// Issue #288 | |
test("Data helper should set proper data instead of a context stack", function () { |
It references this issue: canjs/canjs#288
I’ll update this to only look for the context property when it’s required for that case, or if that issue isn’t valid anymore, I can drop it altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I learned that this function gets called differently depending on whether it’s called as a helper or call expression. I’ve updated the code to do some better duck typing.
1b57db6
to
e428c0f
Compare
This includes a few changes: - Adds the {{domData}} helper that uses can-dom-data - Adds a deprecation warning when {{data}} is used - Fixes {{data}} to accept a value as the second argument - Adds docs for {{domData}} - Includes tests for all these changes Part of canjs/canjs#4044
e428c0f
to
832f121
Compare
This includes a few changes:
{{domData}} in the sidebar nav
{{domData}} signatures
Docs
Docs for passing a value