facebook/fb-flo — pull request #57 by MihaiValentin (2014-07-17 20:39:19+00:00)
Title: Executing client-side code as part of the callback

Hello,

As discussed in #55, here is a suggestion for how this feature can be implemented. I didn't update the documentation with examples, since this approach may change before actually getting merged, so I will do it then.

I take the `update` function, convert it to string, send it through websockets, and eval it inside the fb-flo client extension. In case something is broken, the error is caught and logged to the console. As I said earlier, we will also need to have some small guidelines regarding what you can do and what you can't do in the `update` function.

The example below shows how we can refresh a running app and bringing it back in the same state it was before the resource.

```javascript
callback({
resourceURL: 'lib/' + filepath,
contents: fs.readFileSync('lib/' + filepath),
updated: function(_window, resourceURL) {
var state = _window.myapp.getCurrentState();
_window.myapp.reload(); // this destroys it and re-initializes it
_window.myapp.setCurrentState(state);
}
});
```

Regarding the plugin architecture, I can't think of a simple way to make out-of-the box plugins that update applications written with specific frameworks. For AngularJS at least, you need to write your application in such a way that it can be destroyed and reinitialized. You can't just de-register a service/directive and then register it again with the new code. That's why this logic is to be performed by the developer that's writing the application itself. Of course, we could make a wiki in which we could describe the best approach for structuring apps in various frameworks so that they would work well with `fb-flo`.