01-24-2020 13:22
01-24-2020 13:22
Is there a way that the index.js can access arrays from another .js without having to import them? I am working on a clock face with flash cards on it and the arrays are quite large, they crash the watch face because they take up all the memory when imported into the index.js.
index.js
import * as arrayShort from "./arrayShort.js"; var word1 = document.getElementById("text_wordOne"); var word2 = document.getElementById("text_wordTwo"); var num = 1; let img = document.getElementById("button_next"); //let wordOne = ["","word1.1","word1.2"]; //let wordTwo = arrayWordTwo[num]; word1.text=arrayShort.arrayShortOne[num]; word2.text=arrayShort.arrayShortTwo[num]; img.onclick = (e) => { if (num > 999 || 0) { num = 1 } else { num++; } const displayWords = document.getElementById("displayWords"); word1.text=arrayShort.arrayShortOne[num]; word2.text=arrayShort.arrayShortTwo[num]; displayWords.animate("load"); }
arrayShort.js
export let arrayShortOne = ["","word1.1","word1.2","imported array"]; export let arrayShortTwo = ["","word2.1","word2.2","imported array"];
01-24-2020 13:27
01-24-2020 13:27
I don't think so (using JS import). But you can create a random-access file method using the file system API. It isn't trivially easy, but can be done.
01-24-2020 13:31
01-24-2020 13:31
I think you could use the i18n API for this.
Store all your strings in the language file, then just request them by ID. I think that's what Sergius does in his Poke database. https://github.com/SergioMorchon/fitbit-pokelab-swsh
https://dev.fitbit.com/build/guides/localization/
https://github.com/fitbit/sdk-i18n