[PATCH] Plugins UI: Correctly Load Plugin Tabs

From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> In ui/js/src/kimchi.main.js we fetch all plugin tabs and concat them to the tabs array. However array.concat does not work in place, it creates a new array to store the result, so it does not correctly update the tabs array. The plugin tabs are not loaded at all. This patch fixes the problem by using tabs.push.apply(tabs, pluginTabs) . Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- ui/js/src/kimchi.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js index 9b0acbf..78206bf 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -72,7 +72,7 @@ kimchi.main = function() { var url = kimchi.template(pluginConfigUrl, { plugin: p }); - tabs.concat(retrieveTabs(url)); + tabs.push.apply(tabs, retrieveTabs(url)); }); var firstTabPath = tabs[0] && tabs[0]['path']; -- 1.8.5.3

On 04/03/2014 03:51 PM, zhshzhou@linux.vnet.ibm.com wrote: > From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> > > In ui/js/src/kimchi.main.js we fetch all plugin tabs and concat them to > the tabs array. However array.concat does not work in place, it creates > a new array to store the result, so it does not correctly update the > tabs array. The plugin tabs are not loaded at all. > > This patch fixes the problem by using tabs.push.apply(tabs, pluginTabs) . > > Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> > --- > ui/js/src/kimchi.main.js | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js > index 9b0acbf..78206bf 100644 > --- a/ui/js/src/kimchi.main.js > +++ b/ui/js/src/kimchi.main.js > @@ -72,7 +72,7 @@ kimchi.main = function() { > var url = kimchi.template(pluginConfigUrl, { > plugin: p > }); > - tabs.concat(retrieveTabs(url)); > + tabs.push.apply(tabs, retrieveTabs(url)); No. It's wrong. retrieveTabs() returns an *array*. Consider this: we have 3 plugins, and we'll load them one by one. 1) For the first time, we assign the result of retrieveTabs() to firstTabsArray = ['Admin Function1', 'Admin Function2']. Then we simply copy the reference from firstTabsArray to tabs. 2) For the second time, we get secondTabsArray = ['Admin Function3', 'Admin Function4']. Then tabs should be: ['Admin Function1', 'Admin Function2', 'Admin Function3', 'Admin Function4']. 3) For the third time, we get thirdTabsArray = ['Admin Function5', 'Admin Function6']. Then tabs should be: ['Admin Function1', 'Admin Function2', 'Admin Function3', 'Admin Function4', 'Admin Function5', 'Admin Function6']. If using array.push(), the final result of tabs will become: [ ['Admin Function1', 'Admin Function2'], ['Admin Function3', 'Admin Function4'], ['Admin Function5', 'Admin Function6'] ]. > }); > > var firstTabPath = tabs[0] && tabs[0]['path'];

on 2014/04/03 16:02, Hongliang Wang wrote: > > On 04/03/2014 03:51 PM, zhshzhou@linux.vnet.ibm.com wrote: >> From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> >> >> In ui/js/src/kimchi.main.js we fetch all plugin tabs and concat them to >> the tabs array. However array.concat does not work in place, it creates >> a new array to store the result, so it does not correctly update the >> tabs array. The plugin tabs are not loaded at all. >> >> This patch fixes the problem by using tabs.push.apply(tabs, pluginTabs) . >> >> Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> >> --- >> ui/js/src/kimchi.main.js | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js >> index 9b0acbf..78206bf 100644 >> --- a/ui/js/src/kimchi.main.js >> +++ b/ui/js/src/kimchi.main.js >> @@ -72,7 +72,7 @@ kimchi.main = function() { >> var url = kimchi.template(pluginConfigUrl, { >> plugin: p >> }); >> - tabs.concat(retrieveTabs(url)); > >> + tabs.push.apply(tabs, retrieveTabs(url)); > No. It's wrong. retrieveTabs() returns an *array*. Consider this: we > have 3 plugins, and we'll load them one by one. > 1) For the first time, we assign the result of retrieveTabs() to > firstTabsArray = ['Admin Function1', 'Admin Function2']. Then we simply > copy the reference from firstTabsArray to tabs. > 2) For the second time, we get secondTabsArray = ['Admin Function3', > 'Admin Function4']. Then tabs should be: ['Admin Function1', 'Admin > Function2', 'Admin Function3', 'Admin Function4']. > 3) For the third time, we get thirdTabsArray = ['Admin Function5', > 'Admin Function6']. Then tabs should be: ['Admin Function1', 'Admin > Function2', 'Admin Function3', 'Admin Function4', 'Admin Function5', > 'Admin Function6']. > > If using array.push(), the final result of tabs will become: [ > ['Admin Function1', 'Admin Function2'], ['Admin Function3', 'Admin > Function4'], ['Admin Function5', 'Admin Function6'] ]. Hello, As I tested. var a = [1, 2, 3]; a.push.apply(a, [4, 5]); a.push.apply(a, [6, 7]); alert(a); It prints 1,2,3,4,5,6,7. And I also test it in the Firefox js debug, tabs is correctly extended to a plain array. >> }); >> >> var firstTabPath = tabs[0] && tabs[0]['path']; > > -- Thanks and best regards! Zhou Zheng Sheng / 周征晟 E-mail: zhshzhou@linux.vnet.ibm.com Telephone: 86-10-82454397

On 04/03/2014 03:51 PM, zhshzhou@linux.vnet.ibm.com wrote:
From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
In ui/js/src/kimchi.main.js we fetch all plugin tabs and concat them to the tabs array. However array.concat does not work in place, it creates a new array to store the result, so it does not correctly update the tabs array. The plugin tabs are not loaded at all. Please assign back the concatenated value back to tabs:
tabs = tabs.concat(retrieveTabs(url)); Thanks!
This patch fixes the problem by using tabs.push.apply(tabs, pluginTabs) .
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- ui/js/src/kimchi.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js index 9b0acbf..78206bf 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -72,7 +72,7 @@ kimchi.main = function() { var url = kimchi.template(pluginConfigUrl, { plugin: p }); - tabs.concat(retrieveTabs(url)); + tabs.push.apply(tabs, retrieveTabs(url)); });
var firstTabPath = tabs[0] && tabs[0]['path'];

Reviewed-by: Hongliang Wang <hlwang@linux.vnet.ibm.com> Sorry for my last replies! Please ignore them. I just ran your code and it worked well and Array.prototype.push.apply() has better performance than Array.concat(). Thanks for the fix. On 04/03/2014 03:51 PM, zhshzhou@linux.vnet.ibm.com wrote:
From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
In ui/js/src/kimchi.main.js we fetch all plugin tabs and concat them to the tabs array. However array.concat does not work in place, it creates a new array to store the result, so it does not correctly update the tabs array. The plugin tabs are not loaded at all.
This patch fixes the problem by using tabs.push.apply(tabs, pluginTabs) .
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- ui/js/src/kimchi.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js index 9b0acbf..78206bf 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -72,7 +72,7 @@ kimchi.main = function() { var url = kimchi.template(pluginConfigUrl, { plugin: p }); - tabs.concat(retrieveTabs(url)); + tabs.push.apply(tabs, retrieveTabs(url)); });
var firstTabPath = tabs[0] && tabs[0]['path'];

on 2014/04/03 16:17, Hongliang Wang wrote:
Reviewed-by: Hongliang Wang <hlwang@linux.vnet.ibm.com>
Sorry for my last replies! Please ignore them. I just ran your code and it worked well and Array.prototype.push.apply() has better performance than Array.concat(). Thanks for the fix.
Never mind. Cheers ;-)
On 04/03/2014 03:51 PM, zhshzhou@linux.vnet.ibm.com wrote:
From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
In ui/js/src/kimchi.main.js we fetch all plugin tabs and concat them to the tabs array. However array.concat does not work in place, it creates a new array to store the result, so it does not correctly update the tabs array. The plugin tabs are not loaded at all.
This patch fixes the problem by using tabs.push.apply(tabs, pluginTabs) .
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- ui/js/src/kimchi.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js index 9b0acbf..78206bf 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -72,7 +72,7 @@ kimchi.main = function() { var url = kimchi.template(pluginConfigUrl, { plugin: p }); - tabs.concat(retrieveTabs(url)); + tabs.push.apply(tabs, retrieveTabs(url)); });
var firstTabPath = tabs[0] && tabs[0]['path'];
-- Thanks and best regards! Zhou Zheng Sheng / 周征晟 E-mail: zhshzhou@linux.vnet.ibm.com Telephone: 86-10-82454397

Applied. Thanks. Regards, Aline Manera
participants (4)
-
Aline Manera
-
Hongliang Wang
-
Zhou Zheng Sheng
-
zhshzhou@linux.vnet.ibm.com