Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Created March 8, 2017 10:40
Show Gist options
  • Select an option

  • Save davidsharp/998d0de613178b231f6e58db904ad45f to your computer and use it in GitHub Desktop.

Select an option

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)
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
}
})
@davidsharp

Copy link
Copy Markdown
Author

It's worth pointing out that store.update merges the old object with the new (like setState), so when setting, you only need to set the properties that are changing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment