Skip to content

Instantly share code, notes, and snippets.

@deanrad
Last active August 29, 2015 14:05
Show Gist options
  • Save deanrad/550e4f9b5a22adeaf2d2 to your computer and use it in GitHub Desktop.
Save deanrad/550e4f9b5a22adeaf2d2 to your computer and use it in GitHub Desktop.
Load core Meteor Libraries for a Meteor-style REPL in the browser
var loadScript = function(url){
var d=document;
var s=d.createElement('script');
s.src=url;
(d.head || d.documentElement).appendChild(s)
};
/*needed for reactive-coffee, and meteor*/
loadScript('http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js');
/*Tracker.autorun (as Meteor.run), ReactiveDict (as ReactiveMap), ReactiveVar, and ReactiveObject */
loadScript('https://s3.amazonaws.com/www.chicagogrooves.com/js/mini-meteor.js');
/*If you need jQuery too */
loadScript('https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js');
/*Templating - either HTMLJS (from Blaze), or Teacup*/
//loadScript('https://s3.amazonaws.com/www.chicagogrooves.com/js/meteor-html.js');
//loadScript('https://s3.amazonaws.com/www.chicagogrooves.com/js/teacup.js');
loadScript('https://cdnjs.cloudflare.com/ajax/libs/q.js/1.1.2/q.js');
@deanrad
Copy link
Author

deanrad commented Oct 27, 2014

Just copy and paste this gist' contents into a JavaScript Console, or use this JSFiddle, to play with Tracker, ReactiveDict and ReactiveVar, and HTMLJS in any browser tab, even about:blank!

A few things to try (taken from Meteor Manual )

var favoriteFood = "apples";
var favoriteFoodDep = new Tracker.Dependency;

var getFavoriteFood = function () {
  favoriteFoodDep.depend();
  return favoriteFood;
};

var setFavoriteFood = function (newValue) {
  favoriteFood = newValue;
  favoriteFoodDep.changed();
};

getFavoriteFood();
// "apples"

var handle = Tracker.autorun(function () {
  console.log("Your favorite food is " + getFavoriteFood());
});
// "Your favorite food is apples"

setFavoriteFood("mangoes");
// "Your favorite food is mangoes"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment