-
Notifications
You must be signed in to change notification settings - Fork 9
Clientside DB API
With the clientside DB API you can manage collections of data from the client.
You can already take a look at this project as a angular force example.
On the client you need to subscribe yourself to a collection.
ForceClient forceClient;
ViewCollection hunts;
HuntController() {
forceClient = new ForceClient();
forceClient.connect();
forceClient.onConnected.listen((ConnectEvent ce) {
hunts = forceClient.register("hunters", new Cargo(MODE: CargoMode.LOCAL));
});
}
ViewCollection is an iterable list and can be very useful in combination with angular or polymer.
See below an example of an angular template.
<div class="pure-g" ng-repeat="hunt in hunts">
<a class="title" target="_blank" href="{{hunt.value.url}}">
{{hunt.value.name}}
</a>
</div>
You can add data to the ViewCollection object. In the example below 'hunts' is an instance of ViewCollection.
var hunt = new Hunt.fromJson(value);
hunt.point += 1;
hunts.update(key, hunt);
You can also remove an item from the ViewCollection object.
hunts.remove(key);
On the server you can control what data is coming in and what you are able to see. First of all you need to publish your collections on the server.
Cargo cargo = new Cargo(MODE: CargoMode.MONGODB, conf: {"address": "mongodb://127.0.0.1/test" });
forceServer.publish("hunters", cargo);
You can easily control and validate the data that is coming in as follow.
forceServer.publish("hunters", cargo, validate: (CargoPackage fcp, Sender sender) {
if (fcp.json!=null) {
// Check if the url is a url ...
Hunt hunt = new Hunt.fromJson(fcp.json);
if (!hunt.url.startsWith("http")) {
fcp.cancel();
sender.reply("notify", "url not correct!");
}
}
});
More info about validation!