offscreencanvas-worker-cubes.js 351 B

12345678910111213141516171819
  1. import {init, state} from './shared-cubes.js';
  2. function size(data) {
  3. state.width = data.width;
  4. state.height = data.height;
  5. }
  6. const handlers = {
  7. init,
  8. size,
  9. };
  10. self.onmessage = function(e) {
  11. const fn = handlers[e.data.type];
  12. if (typeof fn !== 'function') {
  13. throw new Error('no handler for type: ' + e.data.type);
  14. }
  15. fn(e.data);
  16. };