This file contains 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
" use this function to toggle vimfiler | |
function! s:vimfiler_toggle() | |
if &filetype == 'vimfiler' | |
execute 'silent! buffer #' | |
if &filetype == 'vimfiler' | |
execute 'enew' | |
endif | |
elseif exists('t:vimfiler_buffer') && bufexists(t:vimfiler_buffer) | |
execute 'buffer ' . t:vimfiler_buffer | |
else |
This file contains 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
// compare newArray and oldArray, copy unchanged oldArray items over to | |
// newArray, hence bypass Angular dirty check for these items | |
function updateCollection(newArray, oldArray) { | |
if (!newArray || !oldArray) return newArray; | |
for (var i = 0; i < newArray.length; i++) { | |
for (var j = 0; j < oldArray.length; j++) { | |
if (angular.equals(newArray[i], oldArray[j])) { | |
newArray[i] = oldArray[j]; | |
break; |
This file contains 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
// inside your controller | |
autorun($scope, function() { | |
Meteor.subscribe('myMeteorCollection'); | |
$scope.myModel = MyMeteorCollection.find().fetch(); | |
}); |
This file contains 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
// change Angular's template delimiter to [[...]] | |
angular.module('myApp') | |
.config(['$interpolateProvider', | |
function($interpolateProvider) { | |
$interpolateProvider.startSymbol('[[').endSymbol(']]'); | |
} | |
]); |
This file contains 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
// for Meteor >= 0.8.0 | |
// load Template.* into $templateCache | |
angular.module('myApp') | |
.run(['$templateCache', function($templateCache) { | |
angular.forEach(Template, function(template, name) { | |
// Meteor uses Template to store its own templates, too | |
// Your template file shouldn't start with _ to avoid conflict | |
if (name[0] !== '_' && name !== 'prototype') { | |
var node = document.createElement('div'); |
This file contains 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
// for Meteor < 0.8.0 | |
// load Template.* into $templateCache | |
angular.module('myApp') | |
.run(['$templateCache', function($templateCache) { | |
angular.forEach(Template, function(render, name) { | |
// Meteor uses Template to store its own templates, too | |
// Your template file shouldn't start with _ to avoid conflict | |
if (name[0] !== '_') $templateCache.put(name, render()); |
This file contains 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
// a reactive block inside a $watch block | |
// in this case, you have to manually stop previous autorun | |
// inside $watch block | |
var myAutorun; | |
$scope.$watch('priceTotal', function() { | |
if (myAutorun) myAutorun.stop() | |
myAutorun = $autorun($scope, function() { | |
var shipping = Session.get('shipping'); | |
$scope.total = $scope.priceTotal + shipping; | |
}); |
This file contains 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
// a reactive block that depends on a collection (Products) | |
// and a session value | |
autorun($scope, function() { | |
Meteor.subscribe('products'); | |
var myCity = Session.get('myCity'); | |
$scope.products = updateCollection(Products.find({city: myCity}).fetch(), $scope.products); | |
}); | |
... | |
// any of following lines will trigger the reactive block above |
This file contains 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
// a reactive block that depends on user account | |
autorun($scope, function() { | |
$scope.user = Meteor.user(); | |
$scope.loggedIn = !!user; | |
}); | |
... | |
// any of following lines will trigger the reactive block above | |
Meteor.loginWithPassword(myEmail, myPassword); | |
Accounts.createUser({email: myEmail, password: myPassword); |
This file contains 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
// bind a Meteor reactive computation to the current scope | |
angular.module('myApp') | |
.factory('autorun', function() { | |
return function(scope, fn) { | |
// wrapping around Deps.autorun | |
var comp = Deps.autorun(function(c) { | |
fn(c); | |
// this is run immediately for the first call | |
// but after that, we need to $apply to start Angular digest |
NewerOlder