Sync Through Dependency Injection

We need a mechanism to inject a syncing behavior that can be shared between model and collection. Let’s create a HipsterSync class that holds our data syncing behavior. Ultimately, the various libraries that rely on HipsterSync will invoke a static method HipsterSync.send() to dispatch the CRUD operation. Before looking at that, however, we need a default behavior that can perform Ajax requests.

library​ hipster_sync;
import​ ​'dart:html'​;
import​ ​'dart:convert'​;
class​ HipsterSync {
static​ _defaultSync(method, model, {options}) {
var​ req = ​new​ HttpRequest();
_attachCallbacks(req, options);, model.url);
// POST ...

Get Dart 1 for Everyone now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.