Goal: Allow user to reference individual array constants by given group name reference in a deployed module
User doesn't know the 'name' of a name=value pair, and needs to extract that value.
User is given a group name and sub-group which is that 'name'
Sample code works as expected in IDE editor window as values are of global scope. When deployed as modules however:
Problem 1) Only the last 'exports=' statement is recognized, meaning there isn't a way to gain access to var C once deployed
Thought I had an answer to that by deploying to two separate modules, but found out:
Problem 2) It doesn't appear possible to embed or nest a require() statement inside another module in order to obtain a reference to the first defined set of constants, in order to define a group.
var C = require("https://github.com . . .");
var GROUPS = require("https://github.com . . .");
The above wont work as the second file retrieved by var GROUPS needs the definitions that are in the first file in order to create the group array definition in the second file.
Summary: User has no access to individual constants, in this case var C
Has access to sub-group names in this case GROUPS.COMPASS
ex: print( GROUPS.COMPASS.E );
var exports={};
var C = {
U : "up",
D : "down",
L : "left",
R : "right",
N : "north",
E : "east",
S : "south",
W : "west",
T : "top",
M : "middle",
B : "bottom"
};
exports = C;
var GROUPS = {
COMPASS : [{N:C.N}, {E:C.E}, {S:C.S}, {W:C.W}],
// COMPASS : [ C.N, C.E, C.S, C.W ],
DIRECTION : [ C.U, C.D, C.L, C.R ],
VERTICAL : [ C.T, C.M, C.B ]
};
exports = GROUPS;
var exports={};
exports.C;
exports.GROUPS;
var C = require("https://github.com/sleuthware/EspruinoDocs/blob/master/modules/moduleConstantsTest.js");
print( C.S );
print( GROUPS.COMPASS );
print( GROUPS.COMPASS.E );
Constants need to be in separate module from group array labels which have their own module.
Open to any option as design not cast in stone. Thanks for taking a looksie
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Sun 2018.09.23
Goal: Allow user to reference individual array constants by given group name reference in a deployed module
User doesn't know the 'name' of a name=value pair, and needs to extract that value.
User is given a group name and sub-group which is that 'name'
Sample code works as expected in IDE editor window as values are of global scope. When deployed as modules however:
Problem 1) Only the last 'exports=' statement is recognized, meaning there isn't a way to gain access to
var C
once deployedThought I had an answer to that by deploying to two separate modules, but found out:
Problem 2) It doesn't appear possible to embed or nest a
require()
statement inside another module in order to obtain a reference to the first defined set of constants, in order to define a group.The above wont work as the second file retrieved by
var GROUPS
needs the definitions that are in the first file in order to create the group array definition in the second file.Summary: User has no access to individual constants, in this case
var C
Has access to sub-group names in this case GROUPS.COMPASS
ex:
print( GROUPS.COMPASS.E );
Constants need to be in separate module from group array labels which have their own module.
Open to any option as design not cast in stone. Thanks for taking a looksie
2 Attachments