Wrapper control serving child control's API

Greetings enyo devs,

I've been wondering if there was a way to wrap a control in a way that it won't affect how the developer interacts with the wrapped control. Let me explain by example.

Let's say want I have a kind named "Demo.Table":

enyo.kind({
name: "Demo.Table",
tag: "table",

selectAll: function() {
// Code that selects lines from the table (css background change)
},

filter: function(matchFunction) {
// Code that filters the table items (using setShowing)
},

someOtherFunc: function() {}
})
Nothing complex. But now, let's say I want to have a bit more complex table with a button to select all and an input field to filter the table. So I create a kind with these wrappers and a table in it:

enyo.kind({
name: "Demo.ComplexTable",

components: [
{kind: "enyo.Button", content: "Select all", ontap: "_selectAll"},
{kind: "enyo.Input", placeholder: "Filter by name", oninput: "_filterByName"},
{kind: "Demo.Table", name: "table", components: [
/*items*/
]}
],

_selectAll: function() {
@$.table.selectAll();
},

_filterByName: function(inSender) {
@$.table.filter(function(item) {return item.name == inSender.getValue()});
}
This kind does what I want. But the problem is that if I want to access the table of a Demo.ComplexTable, I have to use its '$' property.
Given this wrapper only has private methods I want it to be completely transparent for the developer. So that he can call `someOtherFunc` directly on the Demo.ComplexTable kind that will pass it to the real table.

I know I can set the 'controlParentName' property to serve the enyo.Control API of the table but this doesn't solve the custom API problem.

Comments

Sign In or Register to comment.