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

Function init

suning/suning.js:282–324  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

280}
281
282function init() {
283 isSurge = () => {
284 return undefined === this.$httpClient ? false : true
285 }
286 isQuanX = () => {
287 return undefined === this.$task ? false : true
288 }
289 getdata = (key) => {
290 if (isSurge()) return $persistentStore.read(key)
291 if (isQuanX()) return $prefs.valueForKey(key)
292 }
293 setdata = (key, val) => {
294 if (isSurge()) return $persistentStore.write(key, val)
295 if (isQuanX()) return $prefs.setValueForKey(key, val)
296 }
297 msg = (title, subtitle, body) => {
298 if (isSurge()) $notification.post(title, subtitle, body)
299 if (isQuanX()) $notify(title, subtitle, body)
300 }
301 log = (message) => console.log(message)
302 get = (url, cb) => {
303 if (isSurge()) {
304 $httpClient.get(url, cb)
305 }
306 if (isQuanX()) {
307 url.method = 'GET'
308 $task.fetch(url).then((resp) => cb(null, resp, resp.body))
309 }
310 }
311 post = (url, cb) => {
312 if (isSurge()) {
313 $httpClient.post(url, cb)
314 }
315 if (isQuanX()) {
316 url.method = 'POST'
317 $task.fetch(url).then((resp) => cb(null, resp, resp.body))
318 }
319 }
320 done = (value = {}) => {
321 $done(value)
322 }
323 return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
324}

Callers 1

suning.jsFile · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected