Skip to content
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

Attributes typeof 'function' or 'object' #13

Open
godtail opened this issue Jul 14, 2017 · 1 comment
Open

Attributes typeof 'function' or 'object' #13

godtail opened this issue Jul 14, 2017 · 1 comment

Comments

@godtail
Copy link

godtail commented Jul 14, 2017

Description

Typeof function

When I use a attribute name 'link' like this {{ item.link }}, and passed a object { item:[] }, after parse it returns a function like this: function (a){for(var b={},c=0,d=this.length;c<d;c++)for(var e in a)if(a[e](this[c])){b[e]=this[c];delete a[e];break}return b}.

The link function is generation by mootools(item is an Array, and mootools changed the Array.prototype).

So, I need avoid to use link or other special attributes, It's cost a lot of time to check. but for another scene, useful for bind func on onclick.

<button onclick="{{ item.clickFunc }}"></button>

Type of object

For special scene, It's need return the encoded JSON.

<ul class="menu" data-setting="{{ menu.setting }}"></ul>

Now, only for the TextNode.

// parseTextNode
if (node.nodeType === (node.TEXT_NODE || 3)) {
       node.nodeValue = node.nodeValue.replace(VALUE_OUT_REG, (item, $1) => {
               var value = this.parseSodaExpression($1, scope);
               if (typeof value === "object") {
                     value = JSON.stringify(value, null, 2)
                }
                return value;
       });
}

Suggest

From src/soda.js, _getValue function

if (typeof data[attrStr] !== "undefined") {
    rValue = data[attrStr];
}

Ideas

Just ideas, need discuss.

  1. We always focus on the passed objects(sodaScope), and don't care with the attributes on there prototype, add hasOwnProperty to check attributes.

  2. check the element attributes name like 'onclick', bad way!!!

  3. typeof object, use JSON.stringify.

@dorsywang
Copy link
Member

Thank @godtail . It's a good suggestion, Next version we will optimize the output function.

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

No branches or pull requests

2 participants