Last active
December 10, 2015 17:08
-
-
Save bfricka/4465490 to your computer and use it in GitHub Desktop.
Amplify.Store Storage Wrapper
This file contains 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
# 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