This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
/* eslint-disable */
|
||||
import config from "../utils/config";
|
||||
import api from "./apiutil";
|
||||
import _ from "../utils/libs/core.min.js";
|
||||
import { getToken } from "../utils/authUtil";
|
||||
/* eslint-disable */
|
||||
|
||||
/*
|
||||
Locale:
|
||||
Methods
|
||||
@@ -10,7 +11,7 @@ Methods
|
||||
- It stores a local in memory cache of the keys and returns them from cache whenever possible
|
||||
- Method: Get keys one at a time or in an array
|
||||
- a method that accepts lt keys and returns their text
|
||||
- If a key is not in the cache here then it fetches it from the server
|
||||
- If a key is not in the cache here then it returns an obvious error string
|
||||
- Method: pre-fetch / Cache keys
|
||||
- Used to pre-fetch a bunch of keys at once if necessary
|
||||
- A caller will call this with the list of keys it will need in advance, the ones that are not present in the cache will be fetched from the server and the cache populated
|
||||
@@ -24,11 +25,14 @@ Methods
|
||||
const lt = {};
|
||||
|
||||
export default {
|
||||
async Get(keys) {
|
||||
this.PreFetch(keys);
|
||||
//TODO: return they keys / lt array
|
||||
Get(key) {
|
||||
debugger;
|
||||
if (!_.has(lt, key)) {
|
||||
return "?" + key + "?";
|
||||
}
|
||||
return lt[key];
|
||||
},
|
||||
async PreFetch(keys) {
|
||||
async Fetch(keys) {
|
||||
//step 1: build an array of keys that we don't have already
|
||||
var NeedIt = [];
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
@@ -48,8 +52,11 @@ export default {
|
||||
})
|
||||
.then(api.status)
|
||||
.then(api.json)
|
||||
|
||||
.then(() => {
|
||||
.then(response => {
|
||||
_.forEach(response.data, function(item) {
|
||||
lt[item.key] = item.value;
|
||||
});
|
||||
debugger;
|
||||
return Promise.resolve(true);
|
||||
}) //succeeded, nothing to return
|
||||
.catch(function(error) {
|
||||
|
||||
Reference in New Issue
Block a user