rxdb-plugin-proxy
v0.0.3
Published
proxy data plugin for rxdb
Downloads
4
Readme
rxdb-plugin-proxy
proxy data plugin for rxdb
way
see https://github.com/pubkey/rxdb/issues/1269
example
const RxDB = require("rxdb");
RxDB.plugin(require("pouchdb-adapter-memory"));
RxDB.plugin(require("rxdb-plugin-proxy"));
(async () => {
const db = await RxDB.create({
name: "db1",
adapter: "memory"
});
const docSchema = {
version: 0,
type: "object",
properties: {
name: {
type: "string"
}
}
};
const Doc = await db.collection({
name: "doc",
schema: docSchema,
methods: {
// add proxy's methods.
change(name) {
this.name = name; // RXDocument can't call
}
}
});
const doc = await Doc.insert({
name: "first"
});
console.log(doc.name);
const pdoc = doc.proxy();
pdoc.change("leo");
console.log(pdoc.name, doc.name); // real-time out: "leo first"
pdoc.change("leo2");
console.log(pdoc.name, doc.name); // real-time out: "leo2 first"
pdoc.change("leo3");
console.log(pdoc.name, doc.name); // real-time out: "leo3 first"
await pdoc.store(); // save doc
console.log(pdoc.name, doc.name); // out: "leo3 leo3"
})();