Skip to content

Commit

Permalink
Add renderInPlaceholder function
Browse files Browse the repository at this point in the history
  • Loading branch information
marconi1992 committed Aug 28, 2019
1 parent 220ff1d commit 52bb0df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hypernova-svelte",
"version": "1.0.1",
"version": "1.1.0",
"description": "Svelte Bindings for Hypernova",
"main": "lib/index.js",
"author": "Felipe Guizar Diaz <felipegaiacharly@gmail.com>",
Expand All @@ -20,12 +20,15 @@
"lint": "eslint src",
"build": "babel src -d lib"
},
"peerDependencies": {
"hypernova": "^2.5.0"
"dependencies": {
"hypernova": "^2.5.0",
"nova-helpers": "^1.0.1-alpha.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-airbnb": "^2.5.3",
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/runtime": "^7.5.5",
"babel-preset-airbnb": "^4.0.1",
"eslint": "^5.14.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.16.0"
Expand Down
24 changes: 18 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import hypernova, { serialize, load } from 'hypernova';
import { findNode, getData } from 'nova-helpers';

export const something = {};
const mountComponent = (Component, node, data) => {
return new Component({
target: node,
props: data,
hydrate: true,
});
};

export const renderInPlaceholder = (name, Component, id) => {
const node = findNode(name, id);
const data = getData(name, id);

if (node && data) {
mountComponent(Component, node, data);
}
};

export const renderSvelte = (name, Component) => hypernova({
server() {
Expand All @@ -17,11 +33,7 @@ export const renderSvelte = (name, Component) => hypernova({
payloads.forEach((payload) => {
const { node, data: propsData } = payload;

return new Component({
target: node,
props: propsData,
hydrate: true,
});
return mountComponent(Component, node, propsData);
});
}

Expand Down

0 comments on commit 52bb0df

Please sign in to comment.