refactor @saveable to @svDb()
This commit is contained in:
parent
63ceded1b8
commit
7079340657
@ -63,7 +63,7 @@ So to get to get access to a specific collection you document
|
|||||||
|
|
||||||
@Collection(myDb1)
|
@Collection(myDb1)
|
||||||
class myObject extends smartdata.DbDoc<myObject> { // read the next block about DbDoc
|
class myObject extends smartdata.DbDoc<myObject> { // read the next block about DbDoc
|
||||||
@smartdata.saveable property1: string // @smartdata.saveable marks the property for db save
|
@smartdata.svDb() property1: string // @smartdata.svDb() marks the property for db save
|
||||||
property2: number // this one is not marked, so it won't be save upon calling this.save()
|
property2: number // this one is not marked, so it won't be save upon calling this.save()
|
||||||
constructor(optionsArg:{
|
constructor(optionsArg:{
|
||||||
property1: string,
|
property1: string,
|
||||||
|
2
dist/smartdata.classes.dbdoc.d.ts
vendored
2
dist/smartdata.classes.dbdoc.d.ts
vendored
@ -3,7 +3,7 @@ export declare type TDocCreation = 'db' | 'new' | 'mixed';
|
|||||||
/**
|
/**
|
||||||
* saveable - saveable decorator to be used on class properties
|
* saveable - saveable decorator to be used on class properties
|
||||||
*/
|
*/
|
||||||
export declare function saveable(target: DbDoc<any>, key: string): void;
|
export declare function svDb(): (target: DbDoc<any>, key: string) => void;
|
||||||
export declare class DbDoc<T> {
|
export declare class DbDoc<T> {
|
||||||
/**
|
/**
|
||||||
* the collection object an Doc belongs to
|
* the collection object an Doc belongs to
|
||||||
|
8
dist/smartdata.classes.dbdoc.js
vendored
8
dist/smartdata.classes.dbdoc.js
vendored
@ -2,14 +2,16 @@
|
|||||||
/**
|
/**
|
||||||
* saveable - saveable decorator to be used on class properties
|
* saveable - saveable decorator to be used on class properties
|
||||||
*/
|
*/
|
||||||
function saveable(target, key) {
|
function svDb() {
|
||||||
|
return (target, key) => {
|
||||||
console.log('called sva');
|
console.log('called sva');
|
||||||
if (!target.saveableProperties) {
|
if (!target.saveableProperties) {
|
||||||
target.saveableProperties = [];
|
target.saveableProperties = [];
|
||||||
}
|
}
|
||||||
target.saveableProperties.push(key);
|
target.saveableProperties.push(key);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
exports.saveable = saveable;
|
exports.svDb = svDb;
|
||||||
class DbDoc {
|
class DbDoc {
|
||||||
/**
|
/**
|
||||||
* class constructor
|
* class constructor
|
||||||
@ -43,4 +45,4 @@ class DbDoc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.DbDoc = DbDoc;
|
exports.DbDoc = DbDoc;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBT0E7O0dBRUc7QUFDSCxrQkFBeUIsTUFBa0IsRUFBRSxHQUFXO0lBQ3BELE9BQU8sQ0FBQyxHQUFHLENBQUMsWUFBWSxDQUFDLENBQUE7SUFDekIsRUFBRSxDQUFDLENBQUMsQ0FBQyxNQUFNLENBQUMsa0JBQWtCLENBQUMsQ0FBQyxDQUFDO1FBQUMsTUFBTSxDQUFDLGtCQUFrQixHQUFHLEVBQUUsQ0FBQTtJQUFDLENBQUM7SUFDbEUsTUFBTSxDQUFDLGtCQUFrQixDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQTtBQUN2QyxDQUFDO0FBSkQsNEJBSUM7QUFFRDtJQWlCSTs7T0FFRztJQUNIO1FBQ0ksSUFBSSxDQUFDLFVBQVUsR0FBRyxJQUFJLENBQUMsV0FBVyxDQUFDLGNBQWMsQ0FBQyxDQUFBO0lBQ3RELENBQUM7SUFFRDs7O09BR0c7SUFDSCxJQUFJO1FBQ0EsSUFBSSxjQUFjLEdBQUcsRUFBRSxDQUFBO1FBQ3ZCLEdBQUcsQ0FBQyxDQUFDLElBQUksa0JBQWtCLElBQUksSUFBSSxDQUFDLGtCQUFrQixDQU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BQyxDQUFBO0FBQ0wsQ0FBQztBQU5ELG9CQU1DO0FBRUQ7SUFpQkk7O09BRUc7SUFDSDtRQUNJLElBQUksQ0FBQyxVQUFVLEdBQUcsSUFBSSxDQUFDLFdBQVcsQ0FBQyxjQUFjLENBQUMsQ0FBQTtJQUN0RCxDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsSUFBSTtRQUNBLElBQUksY0FBYyxHQUFHLEVBQUUsQ0FBQTtRQUN2QixHQUFHLENBQUMsQ0FBQyxJQUFJLGtCQUFrQixJQUFJLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDLENBQUM7WUFDckQsY0FBYyxDQUFDLGtCQUFrQixDQUFDLEdBQUcsSUFBSSxDQUFDLGtCQUFrQixDQUFDLENBQUE7UUFDakUsQ0FBQztRQUNELE1BQU0sQ0FBQyxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQyxDQUFDO1lBQ3hCLEtBQUssSUFBSTtnQkFDTCxJQUFJLENBQUMsVUFBVSxDQUFBLENBQUMscUNBQXFDO2dCQUNyRCxLQUFLLENBQUE7WUFDVCxLQUFLLEtBQUs7Z0JBQ04sSUFBSSxDQUFDLFVBQVUsQ0FBQyxTQUFTLENBQUMsY0FBYyxDQUFDLENBQUE7UUFDakQsQ0FBQztJQUNMLENBQUM7SUFFRDs7O09BR0c7SUFDSCxRQUFRO1FBQ0osSUFBSSxDQUFDLElBQUksRUFBRSxDQUFBO0lBQ2YsQ0FBQztDQUNKO0FBakRELHNCQWlEQyJ9
|
File diff suppressed because one or more lines are too long
@ -72,7 +72,7 @@ describe('smartdata', function () {
|
|||||||
it('should create an extended class', function () {
|
it('should create an extended class', function () {
|
||||||
@smartdata.Collection(testDb)
|
@smartdata.Collection(testDb)
|
||||||
class TestCar extends smartdata.DbDoc<TestCar> {
|
class TestCar extends smartdata.DbDoc<TestCar> {
|
||||||
@smartdata.saveable
|
@smartdata.svDb()
|
||||||
color: string
|
color: string
|
||||||
constructor(optionsArg: {
|
constructor(optionsArg: {
|
||||||
color: string,
|
color: string,
|
||||||
|
@ -8,11 +8,13 @@ export type TDocCreation = 'db' | 'new' | 'mixed'
|
|||||||
/**
|
/**
|
||||||
* saveable - saveable decorator to be used on class properties
|
* saveable - saveable decorator to be used on class properties
|
||||||
*/
|
*/
|
||||||
export function saveable(target: DbDoc<any>, key: string) {
|
export function svDb() {
|
||||||
|
return (target: DbDoc<any>, key: string) => {
|
||||||
console.log('called sva')
|
console.log('called sva')
|
||||||
if (!target.saveableProperties) { target.saveableProperties = [] }
|
if (!target.saveableProperties) { target.saveableProperties = [] }
|
||||||
target.saveableProperties.push(key)
|
target.saveableProperties.push(key)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class DbDoc<T> {
|
export class DbDoc<T> {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user