Jean-Yves Didier

added an entry in invocations to look up to localstorage

1 -/******/ "use strict";
2 /******/ var __webpack_modules__ = ([ 1 /******/ var __webpack_modules__ = ([
3 /* 0 */ 2 /* 0 */
4 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 3 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
...@@ -1636,18 +1635,33 @@ let Invocation = function (destination, slot, value) { ...@@ -1636,18 +1635,33 @@ let Invocation = function (destination, slot, value) {
1636 * @return an invocation 1635 * @return an invocation
1637 */ 1636 */
1638 Invocation.cast = function (obj, context) { 1637 Invocation.cast = function (obj, context) {
1639 - if (obj.value !== undefined) { 1638 + let component = context.getComponent(obj.destination);
1640 - var component = context.getComponent(obj.destination);
1641 if (component === undefined) { 1639 if (component === undefined) {
1642 console.error("[ARCS] Destination ",obj.destination, " is undefined"); 1640 console.error("[ARCS] Destination ",obj.destination, " is undefined");
1643 } 1641 }
1644 1642
1643 +
1644 + if (obj.value !== undefined) {
1645 return new Invocation(component, obj.slot, obj.value); 1645 return new Invocation(component, obj.slot, obj.value);
1646 } 1646 }
1647 1647
1648 // this one looks odd, seems there is a failure in the logic. 1648 // this one looks odd, seems there is a failure in the logic.
1649 if (obj.ref !== undefined) { 1649 if (obj.ref !== undefined) {
1650 - return new Invocation(context.getComponent(obj.destination), obj.slot, context.getConstant(obj.ref)); 1650 + return new Invocation(component, obj.slot, context.getConstant(obj.ref));
1651 + }
1652 +
1653 + if (obj.storage !== undefined) {
1654 + let data = null;
1655 + if (typeof(localStorage) !== "undefined") {
1656 + let item = localStorage.getItem(storage.key);
1657 + if (item === null) {
1658 + if (typeof (obj.storage.default) !== "undefined") {
1659 + data = obj.storage.default;
1660 + }
1661 + }
1662 + }
1663 +
1664 + return new Invocation(component, obj.slot, data);
1651 } 1665 }
1652 }; 1666 };
1653 1667
......
This diff is collapsed. Click to expand it.
...@@ -13,6 +13,8 @@ Console = ARCS.Component.create( ...@@ -13,6 +13,8 @@ Console = ARCS.Component.create(
13 return ; 13 return ;
14 } 14 }
15 15
16 + if (typeof document === "undefined") return;
17 +
16 var output = document.getElementById(id); 18 var output = document.getElementById(id);
17 19
18 if (output) { 20 if (output) {
......
...@@ -7,9 +7,7 @@ const path=require('path'); ...@@ -7,9 +7,7 @@ const path=require('path');
7 module.exports = function arcsappToJs(options, loaderContext, content) { 7 module.exports = function arcsappToJs(options, loaderContext, content) {
8 // content is here our file arcsapp.json 8 // content is here our file arcsapp.json
9 9
10 -
11 let descr = JSON.parse(content); 10 let descr = JSON.parse(content);
12 - console.log(descr.context.libraries);
13 11
14 let code = `import ARCS from '../../build/arcs.js';\n`; 12 let code = `import ARCS from '../../build/arcs.js';\n`;
15 let libs = []; 13 let libs = [];
......
...@@ -38,18 +38,33 @@ let Invocation = function (destination, slot, value) { ...@@ -38,18 +38,33 @@ let Invocation = function (destination, slot, value) {
38 * @return an invocation 38 * @return an invocation
39 */ 39 */
40 Invocation.cast = function (obj, context) { 40 Invocation.cast = function (obj, context) {
41 - if (obj.value !== undefined) { 41 + let component = context.getComponent(obj.destination);
42 - var component = context.getComponent(obj.destination);
43 if (component === undefined) { 42 if (component === undefined) {
44 console.error("[ARCS] Destination ",obj.destination, " is undefined"); 43 console.error("[ARCS] Destination ",obj.destination, " is undefined");
45 } 44 }
46 45
46 +
47 + if (obj.value !== undefined) {
47 return new Invocation(component, obj.slot, obj.value); 48 return new Invocation(component, obj.slot, obj.value);
48 } 49 }
49 50
50 // this one looks odd, seems there is a failure in the logic. 51 // this one looks odd, seems there is a failure in the logic.
51 if (obj.ref !== undefined) { 52 if (obj.ref !== undefined) {
52 - return new Invocation(context.getComponent(obj.destination), obj.slot, context.getConstant(obj.ref)); 53 + return new Invocation(component, obj.slot, context.getConstant(obj.ref));
54 + }
55 +
56 + if (obj.storage !== undefined) {
57 + let data = null;
58 + if (typeof(localStorage) !== "undefined") {
59 + let item = localStorage.getItem(storage.key);
60 + if (item === null) {
61 + if (typeof (obj.storage.default) !== "undefined") {
62 + data = obj.storage.default;
63 + }
64 + }
65 + }
66 +
67 + return new Invocation(component, obj.slot, data);
53 } 68 }
54 }; 69 };
55 70
......