Skip to content

Commit 7700972

Browse files
authored
frint: support listening to Child App registrations from providers (#398)
1 parent 0ac05da commit 7700972

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

packages/frint/src/App.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ function App(opts = {}) {
6060
throw new Error('Must provide `name` in options');
6161
}
6262

63+
// children - create Observable if root
64+
this._appsCollection = [];
65+
this._apps$ = new BehaviorSubject(this._appsCollection);
66+
6367
// container
6468
const Container = createContainer([
6569
{ name: this.options.providerNames.app, useDefinedValue: this },
@@ -78,10 +82,6 @@ function App(opts = {}) {
7882
this.container.register(provider);
7983
});
8084

81-
// children - create Observable if root
82-
this._appsCollection = [];
83-
this._apps$ = new BehaviorSubject(this._appsCollection);
84-
8585
this.options.initialize.bind(this)();
8686
}
8787

packages/frint/src/App.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* eslint-disable import/no-extraneous-dependencies, func-names, no-new, class-methods-use-this */
22
/* global describe, it */
33
import { expect } from 'chai';
4+
import { take } from 'rxjs/operators/take';
5+
import { last } from 'rxjs/operators/last';
46

57
import App from './App';
68
import createApp from './createApp';
@@ -542,4 +544,34 @@ describe('frint › App', function () {
542544

543545
expect(app.get('foo')).to.equal('original foo [updatedFromCreateApp] [updatedFromInstantiation]');
544546
});
547+
548+
it('can listen for child apps registration from a provider', function (done) {
549+
const Root = createApp({
550+
name: 'RootApp',
551+
providers: [
552+
{
553+
name: '__EXEC__',
554+
useFactory({ app }) {
555+
app.getApps$().pipe(
556+
take(2),
557+
last()
558+
).subscribe(function (appsList) {
559+
expect(appsList.length).to.equal(1);
560+
expect(appsList[0].name).to.equal('ChildApp');
561+
562+
done();
563+
});
564+
},
565+
deps: ['app'],
566+
},
567+
],
568+
});
569+
570+
const Child = createApp({
571+
name: 'ChildApp',
572+
});
573+
574+
const app = new Root();
575+
app.registerApp(Child);
576+
});
545577
});

0 commit comments

Comments
 (0)