UNPKG

bucklescript-tea

Version:
116 lines (102 loc) 3.67 kB
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE 'use strict'; var Block = require("bs-platform/lib/js/block.js"); var Curry = require("bs-platform/lib/js/curry.js"); var Tea_sub = require("./tea_sub.js"); var Tea_task = require("./tea_task.js"); var Web_window_localstorage = require("./web_window_localstorage.js"); function render_event($staropt$star, msg) { var key = $staropt$star !== undefined ? $staropt$star : ""; var enableCall = function (callbacks) { Curry._1(callbacks.on, /* AddRenderMsg */Block.__(0, [msg])); return (function (param) { return Curry._1(callbacks.on, /* RemoveRenderMsg */Block.__(1, [msg])); }); }; return Tea_sub.registration(key, enableCall); } var length = /* Task */[(function (cb) { var match = Web_window_localstorage.length(window); if (match !== undefined) { return Curry._1(cb, /* Ok */Block.__(0, [match])); } else { return Curry._1(cb, /* Error */Block.__(1, ["localStorage is not available"])); } })]; var clear = /* Task */[(function (cb) { var match = Web_window_localstorage.clear(window); if (match !== undefined) { return Curry._1(cb, /* Ok */Block.__(0, [match])); } else { return Curry._1(cb, /* Error */Block.__(1, ["localStorage is not available"])); } })]; function clearCmd(param) { return Tea_task.attemptOpt((function (param) { return ; }), clear); } function key(idx) { return /* Task */[(function (cb) { var match = Web_window_localstorage.key(window, idx); if (match !== undefined) { return Curry._1(cb, /* Ok */Block.__(0, [match])); } else { return Curry._1(cb, /* Error */Block.__(1, ["localStorage is not available"])); } })]; } function getItem(key) { return /* Task */[(function (cb) { var match = Web_window_localstorage.getItem(window, key); if (match !== undefined) { return Curry._1(cb, /* Ok */Block.__(0, [match])); } else { return Curry._1(cb, /* Error */Block.__(1, ["localStorage is not available"])); } })]; } function removeItem(key) { return /* Task */[(function (cb) { var match = Web_window_localstorage.removeItem(window, key); if (match !== undefined) { return Curry._1(cb, /* Ok */Block.__(0, [match])); } else { return Curry._1(cb, /* Error */Block.__(1, ["localStorage is not available"])); } })]; } function removeItemCmd(key) { return Tea_task.attemptOpt((function (param) { return ; }), removeItem(key)); } function setItem(key, value) { return /* Task */[(function (cb) { var match = Web_window_localstorage.setItem(window, key, value); if (match !== undefined) { return Curry._1(cb, /* Ok */Block.__(0, [/* () */0])); } else { return Curry._1(cb, /* Error */Block.__(1, ["localStorage is not available"])); } })]; } function setItemCmd(key, value) { return Tea_task.attemptOpt((function (param) { return ; }), setItem(key, value)); } var LocalStorage = { length: length, clear: clear, clearCmd: clearCmd, key: key, getItem: getItem, removeItem: removeItem, removeItemCmd: removeItemCmd, setItem: setItem, setItemCmd: setItemCmd }; exports.render_event = render_event; exports.LocalStorage = LocalStorage; /* No side effect */