Skip to content

Commit 2b83b1c

Browse files
committed
feat: add mountComponent and helpers
1 parent 785d686 commit 2b83b1c

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hypernova-angular",
3-
"version": "0.1.2",
3+
"version": "0.2.0",
44
"description": "Angular Bindings for Hypernova",
55
"main": "lib/index.js",
66
"author": "Felipe Guizar Diaz <felipegaiacharly@gmail.com>",
@@ -21,18 +21,21 @@
2121
"build": "babel src -d lib"
2222
},
2323
"devDependencies": {
24-
"babel-cli": "^6.26.0",
25-
"babel-preset-airbnb": "^2.5.3",
24+
"@babel/cli": "^7.7.0",
25+
"@babel/core": "^7.7.2",
26+
"@babel/runtime": "^7.7.2",
27+
"babel-preset-airbnb": "^4.1.0",
2628
"eslint": "^5.14.1",
2729
"eslint-config-airbnb-base": "^13.1.0",
2830
"eslint-plugin-import": "^2.16.0"
2931
},
3032
"peerDependencies": {
3133
"@angular/core": ">=5.0.0",
3234
"@angular/platform-browser": ">=5.0.0",
33-
"@angular/platform-server": ">=5.0.0",
3435
"@angular/platform-browser-dynamic": ">=5.0.0",
36+
"@angular/platform-server": ">=5.0.0",
3537
"hypernova": "^2.5.0",
38+
"nova-helpers": "^1.0.1-alpha.0",
3639
"rxjs": ">=5.0.0"
3740
}
3841
}

src/index.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
1212

1313
import { NgModule, ApplicationRef } from '@angular/core';
1414

15+
import { findNode, getData } from 'nova-helpers';
16+
17+
export { load } from 'hypernova';
18+
19+
export const loadById = (name, id) => {
20+
const node = findNode(name, id);
21+
const data = getData(name, id);
22+
23+
if (node && data) {
24+
return {
25+
node,
26+
data,
27+
};
28+
}
29+
30+
return null;
31+
};
32+
1533
const APP_ID = 'hypernova';
1634

1735
export const HYPERNOVA_DATA = 'Hypernova.Data';
@@ -81,6 +99,12 @@ const renderServer = (ServerAppModule, propsData) => {
8199
});
82100
};
83101

102+
export const mountComponent = (Component, Module, node, propsData) => {
103+
const BrowserAppModule = getBrowserAppModule(Component, Module, node, propsData);
104+
105+
platformBrowserDynamic().bootstrapModule(BrowserAppModule);
106+
};
107+
84108
export const renderAngular = (name, Component, Module) => hypernova({
85109
server() {
86110
return async (propsData) => {
@@ -98,9 +122,7 @@ export const renderAngular = (name, Component, Module) => hypernova({
98122
payloads.forEach((payload) => {
99123
const { node, data: propsData } = payload;
100124

101-
const BrowserAppModule = getBrowserAppModule(Component, Module, node, propsData);
102-
103-
platformBrowserDynamic().bootstrapModule(BrowserAppModule);
125+
mountComponent(Component, Module, node, propsData);
104126
});
105127
}
106128
return Component;

0 commit comments

Comments
 (0)