main.js 963 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. (function () {
  2. // connect to server and peers
  3. $.connect();
  4. //$.state.p2p.broker.set($.lib.peer($.state.user.id()));
  5. // insert css first to prevent fouc
  6. var css = $.util.insertCss($.style);
  7. // start vdom main loop, initialize lazy image loader
  8. var view = $.lib.riko.V($.state, $.templates.app);
  9. //$.util.lazyLoader.init();
  10. document.body.innerHTML = "";
  11. document.body.appendChild(view.target);
  12. // bind scroll event
  13. window.onscroll = $.util.throttleRaf($.emit('scroll'));
  14. // auto-update when some files are changed
  15. Glagol.events.on('changed', function (node) {
  16. if (node.path === "/main.js") {
  17. window.location.reload();
  18. }
  19. if (node.path === "/style.styl") {
  20. css.parentElement.removeChild(css);
  21. css = $.util.insertCss($.style);
  22. }
  23. if (node.path.indexOf('/templates') === 0) {
  24. view.update($.state());
  25. }
  26. if (node.path === '/state.js') {
  27. $.connect();
  28. }
  29. })
  30. return view;
  31. })