diff --git a/src/graph/index.js b/src/graph/index.js index 9f31599..7957117 100644 --- a/src/graph/index.js +++ b/src/graph/index.js @@ -1,5 +1,4 @@ import {subscribe, getTodo} from '../todo' -import renderGraph from './render' let graphArea const unsubscribe = { @@ -20,7 +19,7 @@ function toggleGraph() { graphArea = document.createElement('div') document.body.querySelector('.graph-area-container').appendChild(graphArea) const {storage} = getTodo() - renderGraph(graphArea, storage) + loadAndRenderGraph(graphArea, storage) updateTodoSubscription() updateStoreSubscription(storage) return true @@ -34,7 +33,7 @@ function updateTodoSubscription() { unsubscribe.todo = subscribe(function onTodoUpdate() { const {storage} = getTodo() updateStoreSubscription(storage) - renderGraph(graphArea, storage) + loadAndRenderGraph(graphArea, storage) }) } @@ -43,6 +42,12 @@ function updateStoreSubscription(store) { unsubscribe.store() } unsubscribe.store = store.subscribe(function onStoreUpdate() { - renderGraph(graphArea, store) + loadAndRenderGraph(graphArea, store) + }) +} + +function loadAndRenderGraph(node, store) { + System.import('./render').then(({default: renderGraph}) => { + renderGraph(node, store) }) }