Create a gist now

Instantly share code, notes, and snippets.

@mignev /live-queries.html Secret
Last active Sep 18, 2016

Embed
What would you like to do?
Live Queries setup
<!doctype html>
<head>
<meta charset="utf-8">
<title>SashiDo Live Queries Example!</title>
<meta name="description" content="My Parse App">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script type="text/javascript" src="https://unpkg.com/parse@1.9.1/dist/parse.js"></script>
<style type="text/css">
body {padding: 20px;}
</style>
</head>
<body>
<div class="row">
<div class="col-sm-12">
<h1>Live Query Result:</h1>
<pre id="json">Waiting for changes ...</pre></div>
</div>
<script type="text/javascript">
/*
* Your credentials from:
* SashiDo Dashboard > You app > App Settings > Security & Keys
*/
var server_url = 'https://pg-app-xxxxx.scalabl.cloud/1/',
app_id = 'xxxxxx',
javascript_key = 'xxxxx',
classname = '_User';
Parse.initialize(app_id, javascript_key);
Parse.serverURL = server_url;
var ClassObject = Parse.Object.extend(classname);
var query = new Parse.Query(ClassObject);
var subscription = query.subscribe();
subscription.on('create', function(obj)
{
console.log('create', obj.attributes);
});
subscription.on('update', function(obj)
{
console.log('update', obj.attributes);
document.getElementById("json").innerHTML = JSON.stringify(obj.attributes, undefined, 2);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment