Skip to content

Commit 967e9c1

Browse files
committed
fix stuff i broke
1 parent 4b36fe4 commit 967e9c1

File tree

2 files changed

+18
-37
lines changed

2 files changed

+18
-37
lines changed

src/routes/repl/_components/Viewer.html

+12-30
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,12 @@
159159

160160
this.refs.child.addEventListener('load', () => {
161161
replProxy.onPropUpdate = (prop, value) => {
162-
dispatch('binding', { prop, value });
163-
values_store.update(values => Object.assign({}, values, {
164-
[prop]: value
165-
}));
162+
const current = { [prop]: value };
163+
this.fire('data', { current });
166164
};
167165

168-
replProxy.onFetchProgress = (progress) => {
169-
pendingImports = progress;
166+
replProxy.onFetchProgress = pendingImports => {
167+
this.set({ pendingImports });
170168
};
171169

172170
replProxy.handleLinks();
@@ -195,7 +193,7 @@
195193
const destroyComponent = () => {
196194
replProxy.eval(`
197195
if (window.component) {
198-
window.component.\$destroy();
196+
window.component.\destroy();
199197
window.component = null
200198
}
201199
`);
@@ -249,6 +247,8 @@
249247

250248
const { data } = this.get();
251249

250+
console.log('createComponent');
251+
252252
replProxy.eval(`${dom.code}
253253
document.body.innerHTML = '';
254254
window.location.hash = '';
@@ -271,35 +271,17 @@
271271

272272
this.set({ error });
273273
});
274-
275-
// Download the imports (sets them on iframe window when complete)
276-
if (missingImports.length) {
277-
let cancelled = false;
278-
promise = replProxy.fetchImports(bundle);
279-
promise.cancel = () => { cancelled = true };
280-
promise.then(() => {
281-
if (cancelled) return;
282-
ready();
283-
}).catch(error => {
284-
if (cancelled) return;
285-
this.set({ error });
286-
});
287-
}
288274
};
289275

290-
let pendingImports = missingImports.length;
291-
this.set({ pendingImports });
276+
this.set({ pendingImports: missingImports.length });
292277

293278
if (missingImports.length) {
294279
let cancelled = false;
295280

296-
promise = Promise.all(
297-
missingImports.map(id => fetchImport(id, iframe.contentWindow.curl).then(module => {
298-
pendingImports -= 1;
299-
this.set({ pendingImports });
300-
return module;
301-
}))
302-
);
281+
promise = replProxy.fetchImports(bundle, pendingImports => {
282+
this.set({ pendingImports });
283+
});
284+
303285
promise.cancel = () => cancelled = true;
304286

305287
promise

static/repl-runner.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@
5959
return;
6060
}
6161

62-
props.forEach(prop => {
63-
// TODO should there be a public API for binding?
64-
// e.g. `component.$watch(prop, handler)`?
65-
// (answer: probably)
66-
window.component.$$.bound[prop] = value => {
67-
sendMessage({ action:"prop_update", args: { prop, value } })
68-
};
62+
window.component.on('state', ({ changed, current }) => {
63+
for (let prop in changed) {
64+
if (prop in props) {
65+
sendMessage({ action:"prop_update", args: { prop, value: current[prop] } })
66+
}
67+
}
6968
});
7069
}
7170

0 commit comments

Comments
 (0)