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__) => {
...@@ -1635,20 +1634,35 @@ let Invocation = function (destination, slot, value) { ...@@ -1635,20 +1634,35 @@ let Invocation = function (destination, slot, value) {
1635 * @param context {object} the context in which this invocation takes place. 1634 * @param context {object} the context in which this invocation takes place.
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); 1639 + if (component === undefined) {
1641 - 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 } 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);
1665 + }
1652 }; 1666 };
1653 1667
1654 /*ARCS.Invocation.revert = function(obj, context) { 1668 /*ARCS.Invocation.revert = function(obj, context) {
......
This diff is collapsed. Click to expand it.
...@@ -12,6 +12,8 @@ Console = ARCS.Component.create( ...@@ -12,6 +12,8 @@ Console = ARCS.Component.create(
12 if (id === undefined) { 12 if (id === undefined) {
13 return ; 13 return ;
14 } 14 }
15 +
16 + if (typeof document === "undefined") return;
15 17
16 var output = document.getElementById(id); 18 var output = document.getElementById(id);
17 19
......
...@@ -6,10 +6,8 @@ const path=require('path'); ...@@ -6,10 +6,8 @@ const path=require('path');
6 6
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 -
10 9
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 = [];
......
...@@ -37,20 +37,35 @@ let Invocation = function (destination, slot, value) { ...@@ -37,20 +37,35 @@ let Invocation = function (destination, slot, value) {
37 * @param context {object} the context in which this invocation takes place. 37 * @param context {object} the context in which this invocation takes place.
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); 42 + if (component === undefined) {
43 - 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));
53 } 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);
68 + }
54 }; 69 };
55 70
56 /*ARCS.Invocation.revert = function(obj, context) { 71 /*ARCS.Invocation.revert = function(obj, context) {
......