forked from glimmerjs/todomvc-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write binary gbx package and load it
- Loading branch information
1 parent
2e9da65
commit 9a8f6f3
Showing
7 changed files
with
192 additions
and
5,959 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,56 @@ | ||
import App from './main'; | ||
import Application, { DOMBuilder, AsyncRenderer, BytecodeLoader } from '@glimmer/application'; | ||
import { ComponentManager, setPropertyDidChange } from '@glimmer/component'; | ||
import Resolver, { ResolverConfiguration, BasicModuleRegistry } from '@glimmer/resolver'; | ||
import './ui/components/todomvc-app/template.hbs'; | ||
|
||
const app = new App(); | ||
console.log(app) | ||
const containerElement = document.getElementById('app'); | ||
// TODO: generate this somehow? | ||
var resolverConfiguration = { "app": { "name": "glimmer-todomvc", "rootName": "glimmer-todomvc" }, "types": { "application": { "definitiveCollection": "main" }, "component": { "definitiveCollection": "components" }, "helper": { "definitiveCollection": "components" }, "renderer": { "definitiveCollection": "main" }, "template": { "definitiveCollection": "components" } }, "collections": { "main": { "types": ["application", "renderer"] }, "components": { "group": "ui", "types": ["component", "template", "helper"], "defaultType": "component", "privateCollections": ["utils"] }, "styles": { "group": "ui", "unresolvable": true }, "utils": { "unresolvable": true } } }; | ||
|
||
setPropertyDidChange(() => { | ||
app.scheduleRerender(); | ||
}); | ||
fetch('/dist/glimmer-todomvc.gbx') | ||
.then(req => req.arrayBuffer()) | ||
.then(buf => { | ||
// separate data segment from bytecode | ||
let view = new DataView(buf); | ||
let dec = new TextDecoder; | ||
let length = view.getUint32(0); | ||
let json = dec.decode(new Uint8Array(buf, 4, length)); | ||
let data = JSON.parse(json); | ||
let bytecode = buf.slice(4 + length); | ||
|
||
app.registerInitializer({ | ||
initialize(registry) { | ||
registry.register(`component-manager:/${app.rootName}/component-managers/main`, ComponentManager) | ||
} | ||
}); | ||
// resolve modules | ||
data.table = data.table.map(locator => { | ||
if (locator.kind === 'helper') { | ||
let type = locator.meta.factory ? 0 : 1; | ||
return [type, loadModule(locator)]; | ||
} else { | ||
return loadModule(locator); | ||
} | ||
}); | ||
|
||
app.boot(); | ||
function loadModule(locator) { | ||
let res = require(locator.module); | ||
if (locator.name === 'default') { | ||
return res.default || res; | ||
} | ||
|
||
app.renderComponent('todomvc-app', containerElement, null); | ||
return res[locator.name]; | ||
} | ||
|
||
let element = document.getElementById('app'); | ||
|
||
let app = new Application({ | ||
builder: new DOMBuilder({ element }), | ||
renderer: new AsyncRenderer(), | ||
loader: new BytecodeLoader({ data, bytecode }), | ||
resolver: new Resolver(resolverConfiguration, new BasicModuleRegistry(data.meta)), | ||
}); | ||
|
||
app.registerInitializer({ | ||
initialize(registry) { | ||
registry.register(`component-manager:/${app.rootName}/component-managers/main`, ComponentManager); | ||
} | ||
}); | ||
|
||
app.boot(); | ||
app.renderComponent('todomvc-app', element, null); | ||
}); |
Oops, something went wrong.