Skip to content

Commit 3893590

Browse files
committed
container.Base: createItem() => automatically remove items from existing parents #6689
1 parent eb18e73 commit 3893590

File tree

5 files changed

+17
-37
lines changed

5 files changed

+17
-37
lines changed

apps/colors/view/ViewportController.mjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,12 @@ class ViewportController extends Controller {
8989
{windowId} = data,
9090
url = await Neo.Main.getByPath({path: 'document.URL', windowId}),
9191
widgetName = new URL(url).searchParams.get('name'),
92-
widget = me.getReference(widgetName),
93-
widgetParent = widget.up();
92+
widget = me.getReference(widgetName);
9493

9594
me.connectedApps.push(widgetName);
9695

9796
me.getReference(`detach-${widgetName}-button`).disabled = true;
9897

99-
widgetParent.remove(widget, false);
10098
mainView.add(widget)
10199
}
102100
}
@@ -111,12 +109,10 @@ class ViewportController extends Controller {
111109
{appName, windowId} = data,
112110
url = await Neo.Main.getByPath({path: 'document.URL', windowId}),
113111
widgetName = new URL(url).searchParams.get('name'),
114-
widget = me.getReference(widgetName),
115-
widgetParent = widget.up();
112+
widget = me.getReference(widgetName);
116113

117114
// Closing a non-main app needs to move the widget back into its original position & re-enable the show button
118115
if (appName === 'ColorsWidget') {
119-
widgetParent.remove(widget, false);
120116
me.component.insert(me.widgetIndexMap[widgetName], widget);
121117

122118
me.getReference(`detach-${widgetName}-button`).disabled = false

apps/sharedcovid/view/MainContainerController.mjs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,13 @@ class MainContainerController extends ComponentController {
263263
onAppConnect(data) {
264264
let me = this,
265265
name = data.appName,
266-
parentView, style, toolbar, view;
267-
268-
console.log('onAppConnect', name);
266+
style, toolbar, view;
269267

270268
switch(name) {
271269
case 'SharedCovidChart':
272270
view = me.getReference('controls-panel');
273-
parentView = view.parent;
274-
parentView.storeReferences();
271+
272+
view.parent.storeReferences();
275273

276274
toolbar = me.getReference('controls-panel-header');
277275
style = toolbar.style || {};
@@ -301,9 +299,6 @@ class MainContainerController extends ComponentController {
301299
if (view) {
302300
NeoArray.add(me.connectedApps, name);
303301

304-
parentView = parentView ? parentView : view.isTab ? view.up('tab-container') : Neo.getComponent(view.parentId);
305-
parentView.remove(view, false);
306-
307302
Neo.apps[name].on('render', () => {
308303
me.timeout(100).then(() => {
309304
me.getMainView(name).add(view)
@@ -323,8 +318,6 @@ class MainContainerController extends ComponentController {
323318
view = parentView.items[0],
324319
index, style, toolbar;
325320

326-
console.log('onAppDisconnect', name);
327-
328321
switch (name) {
329322
case 'SharedCovid':
330323
Neo.Main.windowClose({
@@ -342,8 +335,6 @@ class MainContainerController extends ComponentController {
342335
if (view) {
343336
NeoArray.remove(me.connectedApps, name);
344337

345-
parentView.remove(view, false);
346-
347338
switch (name) {
348339
case 'SharedCovidChart':
349340
toolbar = me.getReference('controls-panel-header');

examples/component/multiWindowCoronaGallery/ViewportController.mjs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,13 @@ class ViewportController extends Controller {
7373
{appName} = data;
7474

7575
if (appName === 'GalleryControls') {
76-
let controlsPanel = me.getReference('controls-panel'),
77-
{mainView} = Neo.apps[appName];
76+
let {mainView} = Neo.apps[appName];
7877

7978
me.connectedApps.push(appName);
8079

81-
controlsPanel.parent.remove(controlsPanel, false);
82-
8380
this.getReference('header-toolbar').hidden = true;
8481

85-
mainView.add(controlsPanel)
82+
mainView.add(me.getReference('controls-panel'))
8683
}
8784
}
8885

@@ -96,16 +93,12 @@ class ViewportController extends Controller {
9693
{appName, windowId} = data;
9794

9895
if (appName === 'GalleryControls') {
99-
let controlsPanel = me.getReference('controls-panel');
100-
101-
controlsPanel.parent.remove(controlsPanel, false);
102-
10396
me.getReference('header-toolbar').hidden = false;
10497

105-
me.component.add(controlsPanel)
98+
me.component.add(me.getReference('controls-panel'))
10699
}
107100
// Close popup windows when closing or reloading the main window
108-
else if (appName === 'Neo.examples.component.multiWindowCoronaGallery') {console.log('close', me.connectedApps);
101+
else if (appName === 'Neo.examples.component.multiWindowCoronaGallery') {
109102
Neo.Main.windowClose({names: me.connectedApps, windowId})
110103
}
111104
}

examples/component/multiWindowHelix/ViewportController.mjs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ class ViewportController extends Controller {
7878

7979
me.connectedApps.push(appName);
8080

81-
controlsPanel.parent.remove(controlsPanel, false);
82-
8381
this.getReference('header-toolbar').hidden = true;
8482

8583
mainView.add(controlsPanel)
@@ -96,13 +94,9 @@ class ViewportController extends Controller {
9694
{appName, windowId} = data;
9795

9896
if (appName === 'HelixControls') {
99-
let controlsPanel = me.getReference('controls-panel');
100-
101-
controlsPanel.parent.remove(controlsPanel, false);
102-
10397
me.getReference('header-toolbar').hidden = false;
10498

105-
me.component.add(controlsPanel)
99+
me.component.add(me.getReference('controls-panel'))
106100
}
107101
// Close popup windows when closing or reloading the main window
108102
else if (appName === 'Neo.examples.component.multiWindowHelix') {

src/container/Base.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class Container extends Component {
304304
let me = this,
305305
config = {appName: me.appName, parentId: me.id, parentIndex: index, windowId: me.windowId},
306306
defaults = {...me.itemDefaults},
307-
lazyLoadItem, module;
307+
lazyLoadItem, module, parent;
308308

309309
if (defaults) {
310310
if (item.module) {
@@ -328,6 +328,12 @@ class Container extends Component {
328328
}
329329

330330
case 'NeoInstance': {
331+
parent = item.parent;
332+
333+
if (parent && parent !== me) {
334+
parent.remove(item, false)
335+
}
336+
331337
item.set(config);
332338

333339
// In case an item got created outside a stateProvider based hierarchy, there might be bindings or string

0 commit comments

Comments
 (0)