-
Notifications
You must be signed in to change notification settings - Fork 19
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
ko.components params #35
Comments
since there is no way to know if <my-element foo={{qux}} ></my-element> should be converted to <my-element data-bind='foo: qux'></my-element> or <my-element params='foo:qux'></my-element> I suggest using this syntax <my-element foo='((qux))'></my-element> and we can simply implement it by something like this var getAttributeValue = function(attr){
if(attr.value.slice(0,2) !== '((' || attr.value.slice(-2) !=='))') return;
return attr.name + ':' + attr.value.slice(2,-2);
}
ko.punches.utils.addNodePreprocessor(function(node){
if(node.nodeType !== 1)
return null;
var params = node.getAttribute('params');
params = params ? [params] : [];
[].forEach.call(node.attributes,function(attr){
if(attr.name !== 'params'){
var p = getAttributeValue(attr);
if(p) params.push(p), node.removeAttribute(attr.name);
}
});
if(params.length > 0) node.setAttribute('params',params.join(','));
}); i have tested above code and it's working. |
I can't see how cusom attributes can be confused with |
what about this ? <my-element data-bind="visible:some_condition" params="foo: bar "></my-element> if we write something like the following <my-element visible="{{some_condition}}" foo="{{bar}}"></my-element> then how to differentiate between |
I can't say it's not tempting but having both For example: <my-element foo="{{bar}}" visible="{{condition}}" data-bind="attr.title: 'my tooltip'">
</my-element>
<!-- would be transformed to -->
<my-element params="foo: bar, visible: condition" data-bind="attr: {title: 'my tooltip'}">
</my-element> So, all attributes go into |
So that way <div visible="{{condition}}"></div>
<!-- would be transformed to -->
<div data-bind="visible: condition"></div>
<!-- and for custom elements -->
<my-element visible="{{condition}}"></my-element>
<!-- would be transformed to -->
<my-element parmas="visible:condition"></my-element> I have no problem with that, but that doesn't sound about right. we are making an exception for the custom elements.I think we should keep the syntax consistent . |
Angular and Aurelia are using the attribute name itself, like:
|
Angular does this:
I think that you should keep this talk on creating a web components-like syntax like These are really two different topics. |
@LayZeeDK |
Would you be interested in adding a feature to use punches style attributes on ko component params?
From:
To:
I've not began implementing, but thought I would check here to see if there was any interest.
The text was updated successfully, but these errors were encountered: