Reputation: 45
I've got a small firebase app where I'd like to add a change listener (Db Trigger) when another change happens (e.g. particular property has changed it's value to 'listen') and then remove it when that 'trigger value' changes again. Is it possible?
exports.liveLessonPracticeMonitor = functions.database.ref('/some/property/path')
.onWrite((change, context) => {
if (!change.before.exists() && change.after.val() === 'listen') {
// Can I do it here ?
// start another listener.
functions.database.ref('/some/other/property/path')
.onWrite((otherChange, otherContext) => {
// my code
}
} else if (change.before.val() === 'listen' && change.after.val() === 'stop') {
// stop listening what I've subscribed to two lines above
// How to do that?
}
return null
})
Upvotes: 0
Views: 54
Reputation: 50840
I don't think it is possible but if you are trying to do something based on input you get, you can always add if-else
statement to do so. And if you just don't want to do anything you can add a console.log('Invalid Input')
in the last else part. So the actual trigger is just logging a statement than doing anything else...
Upvotes: 1
Reputation: 317447
No, it's not possible. Triggers can't be added or removed programmatically. They must be exported from index.js and deployed using the Firebase CLI.
Upvotes: 1