I’m working on a google extension which is a dictionary lookup app.
And the raw data(let’s say it’s a raw json) has to be requested online.
The example code is below.
let dict: Js.Dict.t(string) = Js.Dict.empty();
let lookup = (key: string): string => {
Js.Dict.get(dict, key)
};
Api.getDictionary() /* type is Js.Promise.t(string) */
|> Js.Promise.then_(tranferToJsDict) /* type is Js.Promise.t(Js.Dict.t(string)) */
I fetch the data somewhere and decode to data structure I prefer.
There is another function named lookup which retrieves the key(parameter)
And it would use dict for looking up.
However, I have no idea how to initialize dict via api promise since we can not mutate the global variable in reasonml.
I guess I need another pattern for this usage.
Any thought?