diff --git a/README.md b/README.md index 207697f8bf..920b53c6db 100644 --- a/README.md +++ b/README.md @@ -287,7 +287,7 @@ TODO - [ ] Change `context` to `contexts`. - [ ] Figure out what a `Context` will be - - [ ] Implement hack to make `global` inherit from `self` + - [x] Implement hack to make `global` inherit from `self` - [ ] Define on `self.registerModel(m: Model)` protocol - [ ] Describe `contexts` - [ ] make simple `index.html` that demos a dummy model diff --git a/lmlayer.js b/lmlayer.js index accd3dda02..ae514702d3 100644 --- a/lmlayer.js +++ b/lmlayer.js @@ -65,4 +65,14 @@ function loadModelClass() { return global.Model; } +/** + * HACK: on Node.JS + tiny-worker, ensure code imported with importScripts() + * has access to the same things defined on self in this file. + */ +if (typeof global !== 'undefined') { + let globalPrototype = Object.getPrototypeOf(global); + Object.setPrototypeOf(self, globalPrototype); + Object.setPrototypeOf(global, self); +} + /*global importScripts*/ diff --git a/models/en-x-test-derek.js b/models/en-x-test-derek.js index 359f216e92..d532b938f7 100644 --- a/models/en-x-test-derek.js +++ b/models/en-x-test-derek.js @@ -18,7 +18,6 @@ class Model { } // TODO: shouldn't this be running in the same scope as the original? -// TODO: test in a browser! if (typeof global !== 'undefined') { - global.Model = Model; -} \ No newline at end of file + global.Model = Model; +}