Skip to content

Conversation

chasenlehara
Copy link
Member

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
{{domData}} in the sidebar nav domdata nav
{{domData}} signatures domdata signatures
Docs domdata use
Docs for passing a value domdata pass value


@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.
Copy link
Member Author

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.
Copy link
Member Author

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];
Copy link
Member Author

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');

Copy link
Member Author

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.

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');
Copy link
Contributor

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

Copy link
Member Author

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) {
Copy link
Contributor

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 ) {

Copy link
Contributor

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.

Copy link
Member Author

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 );
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

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
@chasenlehara chasenlehara merged commit 33c9ebb into master Mar 29, 2018
@chasenlehara chasenlehara deleted the domData-helper branch March 29, 2018 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants