abstracted-firebase
Advanced tools
Comparing version 0.12.0 to 0.12.1
@@ -49,2 +49,18 @@ 'use strict'; | ||
const WatcherEventWrapper = (context) => (handler) => { | ||
return (snapshot, previousChildKey) => { | ||
const event = { | ||
key: snapshot.key, | ||
value: snapshot.val() | ||
}; | ||
if (previousChildKey) { | ||
event.previousChildKey = previousChildKey; | ||
} | ||
const fullEvent = Object.assign({}, event, context); | ||
console.log("FULL EVENT", fullEvent); | ||
return handler(fullEvent); | ||
}; | ||
}; | ||
// tslint:disable:no-implicit-dependencies | ||
(function (FirebaseBoolean) { | ||
@@ -92,5 +108,11 @@ FirebaseBoolean[FirebaseBoolean["true"] = 1] = "true"; | ||
} | ||
console.log("EVENTS:", events); | ||
events.map(evt => { | ||
console.log(`dispatch set for ${evt}`); | ||
const dispatch = WatcherEventWrapper({ | ||
eventType: evt, | ||
targetType: "path" | ||
})(cb); | ||
if (typeof target === "string") { | ||
this.ref(slashNotation(target)).on(evt, cb); | ||
this.ref(slashNotation(target)).on(evt, dispatch); | ||
} | ||
@@ -101,3 +123,3 @@ else { | ||
.deserialize() | ||
.on(evt, cb); | ||
.on(evt, dispatch); | ||
} | ||
@@ -104,0 +126,0 @@ }); |
@@ -45,2 +45,18 @@ import { wait } from 'common-types'; | ||
const WatcherEventWrapper = (context) => (handler) => { | ||
return (snapshot, previousChildKey) => { | ||
const event = { | ||
key: snapshot.key, | ||
value: snapshot.val() | ||
}; | ||
if (previousChildKey) { | ||
event.previousChildKey = previousChildKey; | ||
} | ||
const fullEvent = Object.assign({}, event, context); | ||
console.log("FULL EVENT", fullEvent); | ||
return handler(fullEvent); | ||
}; | ||
}; | ||
// tslint:disable:no-implicit-dependencies | ||
var FirebaseBoolean; | ||
@@ -89,5 +105,11 @@ (function (FirebaseBoolean) { | ||
} | ||
console.log("EVENTS:", events); | ||
events.map(evt => { | ||
console.log(`dispatch set for ${evt}`); | ||
const dispatch = WatcherEventWrapper({ | ||
eventType: evt, | ||
targetType: "path" | ||
})(cb); | ||
if (typeof target === "string") { | ||
this.ref(slashNotation(target)).on(evt, cb); | ||
this.ref(slashNotation(target)).on(evt, dispatch); | ||
} | ||
@@ -98,3 +120,3 @@ else { | ||
.deserialize() | ||
.on(evt, cb); | ||
.on(evt, dispatch); | ||
} | ||
@@ -101,0 +123,0 @@ }); |
@@ -45,2 +45,18 @@ (function (global, factory) { | ||
const WatcherEventWrapper = (context) => (handler) => { | ||
return (snapshot, previousChildKey) => { | ||
const event = { | ||
key: snapshot.key, | ||
value: snapshot.val() | ||
}; | ||
if (previousChildKey) { | ||
event.previousChildKey = previousChildKey; | ||
} | ||
const fullEvent = Object.assign({}, event, context); | ||
console.log("FULL EVENT", fullEvent); | ||
return handler(fullEvent); | ||
}; | ||
}; | ||
// tslint:disable:no-implicit-dependencies | ||
(function (FirebaseBoolean) { | ||
@@ -88,5 +104,11 @@ FirebaseBoolean[FirebaseBoolean["true"] = 1] = "true"; | ||
} | ||
console.log("EVENTS:", events); | ||
events.map(evt => { | ||
console.log(`dispatch set for ${evt}`); | ||
const dispatch = WatcherEventWrapper({ | ||
eventType: evt, | ||
targetType: "path" | ||
})(cb); | ||
if (typeof target === "string") { | ||
this.ref(slashNotation(target)).on(evt, cb); | ||
this.ref(slashNotation(target)).on(evt, dispatch); | ||
} | ||
@@ -97,3 +119,3 @@ else { | ||
.deserialize() | ||
.on(evt, cb); | ||
.on(evt, dispatch); | ||
} | ||
@@ -100,0 +122,0 @@ }); |
@@ -9,3 +9,13 @@ import { SerializedQuery } from "serialized-query"; | ||
} | ||
export declare type FirebaseEvent = "child_added" | "child_removed" | "child_changed" | "child_moved" | "value"; | ||
export declare type IFirebaseWatchEvent = IFirebaseWatchContext & IFirebaseWatchCoreEvent; | ||
export interface IFirebaseWatchContext { | ||
eventType: rtdb.EventType; | ||
targetType: "path" | "query"; | ||
} | ||
export interface IFirebaseWatchCoreEvent { | ||
key: string; | ||
value: any; | ||
previousChildKey?: string; | ||
} | ||
export declare type IFirebaseWatchHandler = (event: IFirebaseWatchEvent) => any; | ||
export declare enum FirebaseBoolean { | ||
@@ -64,3 +74,3 @@ true = 1, | ||
*/ | ||
watch(target: string | SerializedQuery, events: EventType | EventType[], cb: any): void; | ||
watch(target: string | SerializedQuery, events: EventType | EventType[], cb: IFirebaseWatchHandler): void; | ||
unWatch(events?: EventType | EventType[], cb?: any): void; | ||
@@ -67,0 +77,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
export { RealTimeDB, IFirebaseListener, FirebaseBoolean, FirebaseEvent } from "./db"; | ||
export { RealTimeDB, IFirebaseListener, FirebaseBoolean } from "./db"; | ||
export { FileDepthExceeded } from "./errors/FileDepthExceeded"; | ||
@@ -3,0 +3,0 @@ export { UndefinedAssignment } from "./errors/UndefinedAssignment"; |
{ | ||
"name": "abstracted-firebase", | ||
"version": "0.12.0", | ||
"version": "0.12.1", | ||
"description": "Core library supporting 'abstracted-admin' and 'abstracted-client' libraries", | ||
@@ -47,4 +47,4 @@ "license": "MIT", | ||
"@types/rimraf": "^2.0.1", | ||
"abstracted-admin": "^0.9.8", | ||
"abstracted-client": "^0.9.0", | ||
"abstracted-admin": "^0.12.1", | ||
"abstracted-client": "^0.12.1", | ||
"async-shelljs": "^0.1.2", | ||
@@ -51,0 +51,0 @@ "chai": "^4.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
62363
14
1466