Skip to content

Instantly share code, notes, and snippets.

@bfricka
Last active December 10, 2015 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bfricka/4465490 to your computer and use it in GitHub Desktop.
Save bfricka/4465490 to your computer and use it in GitHub Desktop.
Amplify.Store Storage Wrapper
# This is really just an interaction wrapper for amplify
# I prefer this syntax for interacting with storage.
class Stor
# Constructor sets defaults for amplify
# and optionally for expiration and key
constructor: (key, exp) ->
@key = if key? then key else undefined
@exp = if exp? then exp else null
@amp = amplify.store
get: (key = @key) ->
@amp(key)
set: (val, key = @key, exp = @exp) ->
@amp(key, val, { expiration: exp })
remove: (key = @key) ->
@amp(key, null)
empty: ->
self = @
storage = self.amp()
_.each storage, (itm, key) ->
self.amp(key, null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment