O'Reilly logo

Dart 1 for Everyone by Chris Strom

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required