Created
March 8, 2017 10:40
-
-
Save davidsharp/998d0de613178b231f6e58db904ad45f to your computer and use it in GitHub Desktop.
An ill-advised proxy wrapper snippet for react-native-simple-store (needs a proxy polyfill)
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
| import store from 'react-native-simple-store'; | |
| //also requires something like 'proxy-polyfill' | |
| export default new Proxy(store, { | |
| //GET is async, so it's used like `myStore[someID].then(...)` | |
| get: async function (receiver, name) { | |
| return await receiver.get(name) | |
| }, | |
| //SET simply works like `myStore[someID]=someObject` | |
| // (`null` deletes, this lines up with calling for a non-existant value) | |
| set: function (receiver, name, value) { | |
| if(value!==null) receiver.update(name,value) | |
| else receiver.delete(name) | |
| return false | |
| } | |
| }) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's worth pointing out that
store.updatemerges the old object with the new (likesetState), so when setting, you only need to set the properties that are changing.