aboutsummaryrefslogtreecommitdiff
path: root/src/wechat_ffi.mjs
blob: 31d63e16b412e06fbca701dcd6e6066e9196a7a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { Ok, Error } from "./gleam.mjs"
import { NilError, WechatError } from "./wechat/object.mjs"

export function get_app() {
  return getApp();
}

export function run_app(o) {
  App(o);
}

export function run_page(o) {
  Page(o);
}

export function run_component(o) {
  Component(o);
}

export function get_current_pages() {
  return getCurrentPages();
}

export function set_data(p, d, f) {
  return new Promise(resolve => {
    p.setData(d, f);
    resolve(new Ok(p.data))
  })
}

export function decode_uri_component(u) {
  return decodeURIComponent(u);
}

export function select_component(p, c) {
  return p.selectComponent(c);
}

export function set_timeout(cb, d, o) {
  return setTimeout(cb, d, o)
}

export function clear_timeout(id) {
  return clearTimeout(id)
}

export function set_interval(cb, d, o) {
  return setInterval(cb, d, o)
}

export function clear_interval(id) {
  return clearInverval(id)
}

export function page_route(p) {
  return p.route(); 
}

export function obj_new() {
  return {};
}

export function obj_call(o, v) {
  if (typeof(o) == "function") {
    return new Ok(o(v))
  }
  else {
    let e = new WechatError("not a function")
    return new Error(e)
  }
}

export function obj_stringify(o) {
  return JSON.stringify(o);
}

export function obj_dynamic(o) {
  return o;
}

export function obj_get(o, k) {
  let e = new NilError(undefined)
  return k in o ? new Ok(o[k]) : new Error(e);
}

export function obj_set(o, k, v) {
  return {
    ...o,
    [k]: v
  };
}

export function obj_assign(o, n) {
  return Object.assign({}, o, n)
}