-
Notifications
You must be signed in to change notification settings - Fork 40
How callbacks work in River4
I'm working on callbacks in River4. This page describes how it works, while I'm doing the work. Ultimately there will be a page on the blog about this feature.
-
There are two new folders in the River4 folder, the same folder as the river4.js app: data and callbacks. Each sub-folder of callbacks stores scripts that are called on a specific event. The addToRiver folder contains scripts that are called when a new item has been added to the river.
-
Each script in the addToRiver sub-folder is called once for each new object. There's no guarantee of the order in which they run. However I'm pretty sure they can't run concurrently (please check this).
-
The scripts have three globals they can use and/or modify: urlfeed, itemFromParser and itemFromRiver. urlfeed is the HTTP address of the feed, it's identifier. itemFromParser is an object containing all the data we received from FeedParser. itemFromRiver is the actual object in the river for today. You can add data or modify data in this record, and it will be saved to the river. The items you add can be accessed in other callbacks.
-
There is also a localStorage object, that works as it does in nodeRunner. It's a place you can store persistent data that will be around when River4 runs. It's stored in the data sub-folder. Unlike the browser-based localStorage, you can store any type of data, not just strings.
-
How do we indicate from a script that todaysRiver is dirty and must be written?
-
What about callbacks that are running when the day rolls over? We must protect against this, because todaysRiver is changed by day rollover.
-
How often to save localStorage? I have it done in the everyMinute script. In nodeRunner it's in everySecond. I'm not sure about the tradeoffs.