1
0

helpers.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. define(["./boot", "./junk-drawer", "require"], function (boot, $goodies, require) {
  2. var globals = boot.globals,
  3. exports = {},
  4. extend = $goodies.extend,
  5. api = boot.api;
  6. // API
  7. exports.popupHelios = function () {
  8. require(['helios/index'], function (helios) {
  9. helios.popup();
  10. }, function (err) {
  11. window.alert("Error loading helios.\nIf not present, you can install it with 'npm install @ambers/helios --save-dev'.\nThe error follows:\n" + err);
  12. });
  13. };
  14. Object.defineProperty(exports, "api", {
  15. value: api,
  16. enumerable: true, configurable: true, writable: false
  17. });
  18. Object.defineProperty(exports, "globals", {
  19. value: globals,
  20. enumerable: true, configurable: true, writable: false
  21. });
  22. Object.defineProperty(exports, "$nil", {
  23. value: boot.nilAsReceiver,
  24. enumerable: true, configurable: true, writable: false
  25. });
  26. Object.defineProperty(exports, "nil", {
  27. value: boot.nilAsValue,
  28. enumerable: true, configurable: true, writable: false
  29. });
  30. function settingsInLocalStorage () {
  31. var storage = 'localStorage' in global && global.localStorage;
  32. if (storage) {
  33. var fromStorage;
  34. try {
  35. fromStorage = JSON.parse(storage.getItem('amber.SmalltalkSettings'));
  36. } catch (ex) {
  37. // pass
  38. }
  39. extend(globals.SmalltalkSettings, fromStorage || {});
  40. if (typeof window !== "undefined") {
  41. window.addEventListener('beforeunload', function () {
  42. storage.setItem('amber.SmalltalkSettings', JSON.stringify(globals.SmalltalkSettings));
  43. });
  44. }
  45. }
  46. }
  47. exports.initialize = function (options) {
  48. return new Promise(function (resolve) {
  49. globals.SmalltalkSettings['transport.defaultAmdNamespace'] = "amber/core";
  50. api.amdRequire = require; // TODO better
  51. settingsInLocalStorage();
  52. extend(globals.SmalltalkSettings, options || {});
  53. resolve(api.initialize());
  54. });
  55. };
  56. exports.loadPackages = function (modules) {
  57. return new Promise(function (resolve, reject) {
  58. require(modules, resolve, reject);
  59. }).then(function () {
  60. return globals.Smalltalk._postLoad();
  61. });
  62. };
  63. exports.beClean = function () {
  64. return globals.Smalltalk._beClean();
  65. };
  66. // Exports
  67. return exports;
  68. });