This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Scores collection | |
| // [{ user: 'Alice', score: 2 }, | |
| // { user: 'Alice', score: 1 }, | |
| // { user: 'Bob', score: 4 }] | |
| // Create leaderboard | |
| var agg = new Kinvey.Aggregation(); | |
| agg.on('user'); | |
| agg.setInitial({ total: 0 }); | |
| agg.setReduce(function(doc, out) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var entity = new Kinvey.Entity('my-collection'); | |
| entity.set('key', 'value'); | |
| entity.save({ | |
| success: function(entity) { | |
| var value = entity.get('key'); | |
| // value == "value" | |
| // Entity is now created, lets update another field. | |
| entity.set('foo', 'bar'); | |
| entity.save({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var xhr = new XMLHttpRequest(); | |
| xhr.open('GET', 'https://baas.kinvey.com/appdata/kidXXXX', true); | |
| xhr.setRequestHeader('Authorization', 'Basic foo:bar'); | |
| // Enable the line below to provide Android support. | |
| //xhr.setRequestHeader('X-Kinvey-Origin', 'http://www.example.com'); | |
| xhr.onload = function() { | |
| console.log("LOADED", this.status, this.responseText); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| navigator.geolocation.getCurrentPosition(function(position) { | |
| var coords = position.coords; | |
| var entity = new Kinvey.Entity({ | |
| _geoloc: [coords.longitude, coords.latitude] | |
| }, 'test-collection'); | |
| entity.save({ | |
| success: function(entity) { | |
| // entity is now saved. | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var entity = new Kinvey.Entity({/*attributes*/}, 'collection', { | |
| store: 'cached' | |
| }); | |
| var collection = new Kinvey.Collection('collection', { | |
| store: 'cached' | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var entity = new Kinvey.Entity({/*attributes*/}, 'collection', { | |
| store: 'cached', | |
| options: { policy: 'cachefirst' } | |
| }); | |
| entity.load('my-entity', { | |
| success: function(response) { | |
| // response is the entity instance. | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var collection = new Kinvey.Collection('scores', { | |
| store: 'cached', | |
| options: { policy: 'cachefirst' } | |
| }); | |
| // The leaderboard should override the collections cachefirst policy. | |
| var leaderboard = new Kinvey.Aggregation().on('player'); | |
| collection.aggregate(leaderboard, { | |
| policy: 'nocache',// Overrides cachefirst policy. | |
| success: function(response) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Kinvey.init({ | |
| appKey: '<your-app-key>', | |
| appSecret: '<your-app-secret>', | |
| sync: true | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var entity = new Kinvey.Entity({/*attributes*/}, 'collection', { | |
| store: 'offline', | |
| options: { policy: 'cachefirst' }// Optional, caching policy. | |
| }); | |
| var collection = new Kinvey.Collection('collection', { | |
| store: 'offline', | |
| options: { policy: 'cachefirst' }// Optional, caching policy. | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Kinvey.Sync.configure({ | |
| conflict: Kinvey.Sync.serverAlwaysWins | |
| /* or: | |
| conflict: Kinvey.Sync.clientAlwaysWins | |
| */ | |
| }); |