MCPcopy Create free account
hub / github.com/chavyleung/scripts / init

Function init

haidilao/hdl.js:55–106  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53}
54
55function init() {
56 isSurge = () => {
57 return undefined === this.$httpClient ? false : true
58 }
59 isQuanX = () => {
60 return undefined === this.$task ? false : true
61 }
62 getdata = (key) => {
63 if (isSurge()) return $persistentStore.read(key)
64 if (isQuanX()) return $prefs.valueForKey(key)
65 }
66 setdata = (key, val) => {
67 if (isSurge()) return $persistentStore.write(key, val)
68 if (isQuanX()) return $prefs.setValueForKey(key, val)
69 }
70 msg = (title, subtitle, body) => {
71 if (isSurge()) $notification.post(title, subtitle, body)
72 if (isQuanX()) $notify(title, subtitle, body)
73 }
74 log = (message) => console.log(message)
75 get = (url, cb) => {
76 if (isSurge()) {
77 $httpClient.get(url, cb)
78 }
79 if (isQuanX()) {
80 url.method = 'GET'
81 $task.fetch(url).then((resp) => cb(null, {}, resp.body))
82 }
83 }
84 post = (url, cb) => {
85 if (isSurge()) {
86 $httpClient.post(url, cb)
87 }
88 if (isQuanX()) {
89 url.method = 'POST'
90 $task.fetch(url).then((resp) => cb(null, {}, resp.body))
91 }
92 }
93 put = (url, cb) => {
94 if (isSurge()) {
95 $httpClient.put(url, cb)
96 }
97 if (isQuanX()) {
98 url.method = 'PUT'
99 $task.fetch(url).then((resp) => cb(null, {}, resp.body))
100 }
101 }
102 done = (value = {}) => {
103 $done(value)
104 }
105 return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, put, done }
106}

Callers 1

hdl.jsFile · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected