Receive notification when a fact is added or removed from query results. The notification function will initially recieve all matching facts. It will then subsequently receive new facts as they are created.
watch<T, U, V>(
start: T,
preposition: Preposition<T, U>,
resultAdded: (result: U) => V,
resultRemoved: (model: V) => void
): Watch<U, V>;
j.for
Watch
object that can be used to nest new watches or stop watchingWatch for new facts. Display them to the user as they arrive.
function displayMessage(m) {
// Update the user interface
}
function messagesInChannel(c) {
return j.match({
type: 'Chat.Message',
channel: c
});
}
j.watch(channel, j.for(messagesInChannel), displayMessage);
Remove facts that no longer match the query.
This will occur if the template function has a condition that later becomes false.
The resultAdded
function must return a value.
This value will be pased to resultRemoved
when the condition changes.
function displayMessage(m) {
// Update the user interface
return domElement;
}
function removeMessage(domElement) {
// Remove the message from the user interface
}
function messagesInChannel(c) {
return j.match({
type: 'Chat.Message',
channel: c
}).suchThat(j.not(messageIsRedacted));
}
function messageIsRedacted(m) {
return j.exists({
type: 'Chat.Message.Redacted',
message: m
});
}
j.watch(channel, j.for(messagesInChannel), displayMessage, removeMessage);