I have this JS code, and my functions change variable ‘index’, but not in module.exports. How can i fix it?
var Observable = require("FuseJS/Observable");
var Bundle = require("FuseJS/Bundle");
var stages = Observable();
stages = JSON.parse(Bundle.readSync("stages.json"));
var index = stages.nTag;
console.log(JSON.stringify(stages.Stage1[index]));
function onVar1(context) {
index = stages.Stage1[index].Var1.tag;
}
function onVar2(context) {
index = stages.Stage1[index].Var2.tag;
}
module.exports = {
stages: stages.Stage1[index],
onVar1: onVar1,
onVar2: onVar2
};
I did not understand the philosophy of working with Observable
This code working fine
var Observable = require("FuseJS/Observable");
var Bundle = require("FuseJS/Bundle");
//
var stages = JSON.parse(Bundle.readSync("stages.json"));
var index = stages.nTag;
var st = Observable(stages.Stage1[index]); //new var for exports
function onVar1(context) {
index = stages.Stage1[index].Var1.tag;
st.value = stages.Stage1[index]; //change value in exports
}
function onVar2(context) {
index = stages.Stage1[index].Var2.tag;
st.value = stages.Stage1[index]; //there too
}
module.exports = {
nstages: st,
onVar1: onVar1,
onVar2: onVar2
};