aurajs / aura

A scalable, event-driven JavaScript architecture for developing component-based applications.
MIT License
2.94k stars 255 forks source link

nested components cause , the component creation of multiple times.. #298

Open atamer opened 11 years ago

atamer commented 11 years ago
<div data-aura-widget="../js/widgets/accordion">
 
<div data-aura-id="tckninput" data-aura-widget="../js/widgets/input"></div>
</div>

and here is my accordion widget render method

render: function() {
var str = template({tabs: this.nodes });
this.html(str);
return this;
}

and aura starts

var aura = new Aura({debug:'true', logEvents: 'true'});
aura.use('auraexbackbone')
.use('auraexhandlebars')
.use('auraexstep')
.start({widget:"body"}).then(function(){
console.warn('started!');
});

tckninput component created twice and event trigger twice

atamer commented 11 years ago

I found the problem in component.js aura widgets are searched for whole document

Component.parseList = function(components) {
...
...
core.dom.find(selector, components || 'body').each(function() {
var ns = "aura";
if (appNamespace && (this.getAttribute('data-' + appNamespace +'-component') || this.getAttribute('data-' + appNamespace +'-widget'))) {
ns = appNamespace;
}
var options = parseComponentOptions(this, ns);
list.push({ name: options.name, options: options });
});
};

I want to load these widgets one by one , from root to leaf so I changed this code from

base.dom = {
find: function(selector, context) {
context = context || document;
return $(context).find(selector);
},

to

base.dom = {
find: function(selector, context) {
context = context || document;
if($(context).find(selector).size() > 0){
var children = $(context);
while(true){
var foundSelector = $(children).children(selector);
if(foundSelector.size() > 0){
return foundSelector;
}else{
children = children.children();
}
}
}else{
//null
return $(context).find(selector);
}
},
atamer commented 11 years ago

looks like working , any idea ?

sbellity commented 11 years ago

Hey @atamer,

Would you have time to chat directly with me today ? My Gtalk is stephane@hull.io or you can find me on Freenode : #aurajs

atamer commented 11 years ago

That would be great pleasure , i will be online on gtalk in 2 hours , is it appropriate ? On Jul 22, 2013 6:07 PM, "Stephane Bellity" notifications@github.com wrote:

Hey @atamer https://github.com/atamer,

Would you have time to chat directly with me today ? My Gtalk is stephane@hull.io or you can find me on Freenode : #aurajs

— Reply to this email directly or view it on GitHubhttps://github.com/aurajs/aura/issues/298#issuecomment-21350319 .

sbellity commented 11 years ago

Yep, just ping me when you are available

atamer commented 11 years ago

Hi Stephane, i am online now ..

On Mon, Jul 22, 2013 at 6:36 PM, Stephane Bellity notifications@github.comwrote:

Yep, just ping me when you are available

— Reply to this email directly or view it on GitHubhttps://github.com/aurajs/aura/issues/298#issuecomment-21352647 .

addyosmani commented 11 years ago

I was just wondering if you guys had a chance to discuss this further and if so, what the resolutions on the nested components suggestion might have been (just in case others are interested too). If you feel that there's nothing more to add to this issue, let's close 'er :)