Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App: new `setRegions` method #37

Merged
merged 2 commits into from Oct 31, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

app: allow setting multiple regions for a Widget.

  • Loading branch information...
fahad19 committed Oct 30, 2016
commit 96d6e99bea0705fe1e7142792acd848927bed48e
@@ -165,12 +165,12 @@ class BaseApp {
return this.options[key];
}

registerWidget(WidgetApp, regionName) {
registerWidget(widgetApp, regionName) {
if (!Array.isArray(this.widgetsByRegion[regionName])) {
this.widgetsByRegion[regionName] = [];
}

this.widgetsByRegion[regionName].push(WidgetApp);
this.widgetsByRegion[regionName].push(widgetApp);

return this.widgetsSubject.next(this.widgetsByRegion);
}
@@ -205,13 +205,19 @@ class BaseApp {
* by doing Widget.setRegion()
*/
setRegion(regionName) {
return this.setRegions([regionName]);
}

setRegions(regionNames) {
const rootApp = this.getRootApp();

if (!rootApp) {
throw new Error('No root app instance available, so cannot set region.');
}

return rootApp.registerWidget(this, regionName);
return regionNames.forEach((regionName) => {
return rootApp.registerWidget(this, regionName);
});
}

getWidgets(regionName = null) {
@@ -212,6 +212,17 @@ describe('createApp', function () {
expect(window.app.getStore('blah')).to.equal(null);
});

it('sets multiple regions for a widget', function () {
window.app = new CoreApp();

const widget = new WidgetApp();

widget.setRegions(['header', 'footer']);

expect(window.app.getWidgets('header')).to.deep.equal([widget]);
expect(window.app.getWidgets('footer')).to.deep.equal([widget]);
});

it('throws error if setRegion is called without a root app', function () {
const widget = new WidgetApp();

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.