kutaisan-react-native-mmkv-storage
Version:
This library aims to provide a fast & reliable solution for you data storage needs in react-native apps. It uses [MMKV](https://github.com/Tencent/MMKV) by Tencent under the hood on Android and iOS both that is used by their WeChat app(more than 1 Billion
37 lines (32 loc) • 856 B
JavaScript
export default class transactions {
constructor() {
this.beforewrite = {};
this.onwrite = {};
this.onread = {};
this.ondelete = null;
}
register(type, transaction, mutator) {
if (!transaction || !type || !mutator)
throw new Error("All parameters are required");
if (transaction === "ondelete") {
this[transaction] = mutator;
} else {
this[transaction][type] = mutator;
}
return () => this.unregister(type, transaction);
}
unregister(type, transaction) {
if (!key || !transaction) throw new Error("All parameters are required");
if (transaction === "ondelete") {
this.ondelete = null;
return;
}
this[transaction][type] = null;
}
clear() {
this.beforewrite = {};
this.onread = {};
this.onwrite = {};
this.ondelete = null;
}
}