Created
December 19, 2020 03:55
-
-
Save rgchris/8621b68fd54cf6750d8e4668c8c97004 to your computer and use it in GitHub Desktop.
HTML5 Storage Scheme for Ren-C (In-Browser)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Rebol [ | |
| Title: "Storage Scheme" | |
| Date: 18-Dec-2020 | |
| Author: "Christopher Ross-Gill" | |
| ] | |
| make object! [ | |
| storage-enabled?: js-native [] { | |
| return reb.Logic( | |
| typeof Storage !== 'undefined' | |
| ) | |
| } | |
| storage-set: js-native [ | |
| key [text!] | |
| value [any-value!] | |
| ] { | |
| var key = reb.ArgR('key'), value = reb.ArgR('value'); | |
| localStorage.setItem(reb.Spell(key), reb.Spell(value)); | |
| } | |
| storage-get: js-native [ | |
| key [text!] | |
| ] { | |
| var key = reb.ArgR('key'), value; | |
| value = localStorage.getItem(reb.Spell(key)); | |
| if (typeof value !== 'undefined' && value !== null) { | |
| return reb.Text(value); | |
| } | |
| } | |
| sys/make-scheme [ | |
| Title: "Browser Storage API" | |
| Name: 'storage | |
| Init: func [port [port!]] [ | |
| if not storage-enabled? [ | |
| fail "Local Storage Not Supported" | |
| ] | |
| ] | |
| Actor: [ | |
| copy: func [port] [ | |
| storage-get port/spec/host | |
| ] | |
| insert: func [port value] [ | |
| storage-set port/spec/host value | |
| ] | |
| ] | |
| ] | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment