Skip to content

Clojurescript wrapper around react-native's AsyncStorage using core.async

License

Notifications You must be signed in to change notification settings

glittershark/core-async-storage

Repository files navigation

Core.Async Storage Build Status

A Clojurescript wrapper around react-native's AsyncStorage using core.async

Installation

Clojars Project

Usage

In general, all exposed functions are kebab-case versions of AsyncStorage's camelCase functions, that return a core.async channel instead of taking a callback as their last argument, and also convert all input values to EDN and read all return values as Clojure data structures

(ns my-ns.core
 (:require [glittershark.core-async-storage :refer [get-item set-item]]
           [cljs.core.async :refer [<!]])
 (:require-macros [cljs.core.async.macros :refer [go]]))

(go
  (<! (set-item :foo {:bar "baz"})) ;; => [nil], or [error]
  (println (<! (get-item :foo))))   ;; => [nil {:bar "baz"}], or [error nil]

(let [a-map {:a "foo" :b "bar"}
      a-vec [[:a "foo"][:b "bar"]]]
  (go
    ;; multi-set can accept a map or a collection of vectors
    (println (<! (multi-set a-map)))
    (println (<! (multi-set a-vec))))

Result channels use core.async's promise-chan, so you can read from them as often as you like and they'll always yield the same value

(go
  (let [result (get-item :foo)]
    (println (<! result))   ;; => [nil {:bar "baz"}]
    (println (<! result)))) ;; => [nil {:bar "baz"}]

TODO

  • AsyncStorage.getItem
  • AsyncStorage.setItem
  • AsyncStorage.removeItem
  • AsyncStorage.mergeItem
  • AsyncStorage.clear
  • AsyncStorage.getAllKeys
  • AsyncStorage.flushGetRequests
  • AsyncStorage.multiGet
  • AsyncStorage.multiSet
  • AsyncStorage.multiRemove
  • AsyncStorage.multiMerge

License

Copyright © 2017 Griffin Smith

Distributed under the MIT License.

About

Clojurescript wrapper around react-native's AsyncStorage using core.async

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •