Add an interface to subscribe to root CID changes
Summary
Problem
Developers need to poll the filesystem to detect changes.
Impact
Extra work and complexity for developers.
Solution
Add an interface to subscribe to any change to WNFS. The interface should notify developers when a change occurs locally and remotely.
Detail
It's currently possible to add a callback to the WNFS publish hooks, which are called when a change is made locally. We can likely use the existing work as a starting point or hook into it.
A couple of rough ideas for how we might implement this feature:
- Add an event emitter that emits local and remote change events
- Make the event emitter available to developers at webnative initialization
- Emit local events based on existing publish hooks
- After each local event, poll internally for remote changes and and emit an event when change is confirmed remotely
Note that this would be a first quick implementation with a focus on getting it working and establishing a good interface. A subsequent implementation could set up PubSub with the server over a websockets channel to remove the internal polling.