i got the error :
Exception in template helper: TypeError: time.tz is not a function
with the code :
Template.registerHelper( 'timeAgo', function ( timestamp ) {
if ( timestamp ) {
let time = moment( timestamp ),
let timezone = Session.get("timezone");
return time.tz(timezone).fromNow();
}
});
i have installed the momentjs:moment and it works fine.
the problem is with the timezone package : i have installed the aldeed:moment-timezone package , then i tried with the mrt:moment-timezone package but nothing ; it doesn't work either.
Maybe you loaded moment using something like:
var moment = require('moment');
instead of:
var moment = require('moment-timezone');
Related
This question seems to be more or less a duplicate of this one, but that one received no answers and is over 2 years old so I don't know what the protocol is (I tried to find out).
Anyway, I've written an ASP.NET MVC5 web app and it all works fine in debug. After publishing to the server with the Release configuration I started seeing the error "Uncaught ReferenceError: Cannot access 'n' before initialization".
After many hours of trawling through the code I think I've isolated the issue. I have this small function (it's a Knockout view model, but that's irrelevant):
eventIndexViewModel = function (params) {
let self = this;
// Map values from params object to properties of self
for (const [key, value] of Object.entries(params)) {
self['_' + key] = value;
}
self.eventsView = ko.observable(self._eventsView);
self.calendarToggleButtonClass = ko.pureComputed(function () {
return self.eventsView() === "calendar" ? "active" : "";
});
self.tableToggleButtonClass = ko.pureComputed(function () {
return self.eventsView() === "table" ? "active" : "";
});
};
After being minified and published to the server, if I view the source in the dev tools console it looks like this:
eventIndexViewModel = function(n) {
let t = this;
for (const [n,i] of Object.entries(n))
t["_" + n] = i;
t.eventsView = ko.observable(t._eventsView);
t.calendarToggleButtonClass = ko.pureComputed(function() {
return t.eventsView() === "calendar" ? "active" : ""
});
t.tableToggleButtonClass = ko.pureComputed(function() {
return t.eventsView() === "table" ? "active" : ""
})
}
It is overkill to map the properties for the params object in this way in this particular instance, but I have much larger view models with many more properties in the same project and I want to keep them code consistent, so go with it.
Unless I'm misunderstanding something, the minified version has renamed both the params variable and the key variable in the for statement to n, and I think that is what is causing my error. Certainly, that line with the for statement is where the error is thrown.
Am I understanding the cause of this problem correctly? If so, is it a bug in the minification process? And either way, how can I get around it?
when i test ?_escaped_fragment_= , i get
TypeError: 'undefined' is not a function (evaluating 'document.querySelectorAll.bind(document)')
http://localhost:3000/packages/material-design.js?e252ae03c7066a6ce33a348a22662a73cee8811e:75
http://localhost:3000/packages/material-design.js?e252ae03c7066a6ce33a348a22662a73cee8811e:315
http://localhost:3000/packages/material-design.js?e252ae03c7066a6ce33a348a22662a73cee8811e:318
http://localhost:3000/packages/material-design.js?e252ae03c7066a6ce33a348a22662a73cee8811e:778
The html in the body does show up but I do not get any meta tags and there is a huge blank space in the head before the title.
i followed http://www.meteorpedia.com/read/spiderable/ and ran phantomjs phantomtest.js
❯ phantomjs phantomtest.js [17:50:01]
Loading page...
Page load status: success
not ready, Meteor undefined
i got this.
Any idea what's wrong? Thanks.
In phantomjs, which is used by spiderable, the bind method is not supported. If you're the owner of material-design I would suggest replacing bind with _.bind. Otherwise, you can add a polyfill to your project to make sure that Function.prototype.bind is properly defined.
EDIT
To make sure your browser supports bind put this code somewhere in your code base:
if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) {
if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function() {},
fBound = function() {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
The above implementation is copy/pasted from here.
i am stuck with this for few days now.
I have route with resolve, which looks something like this:
.when('/list/',{
controller : 'list',
templateUrl : 'template/list.stache',
resolve : {
list : function($q,$firebase){
var d = $q.defer(),
ref = new Firebase(_config.url+'/list/');
ref.once('value', function(s){
if(s.val() == null){
d.reject('Object not found');
}
d.resolve($firebase(ref));
});
return d.promise;
}
}
})
It works great in any browser, for some reason it fails in Android app ( using phonegap ), it loads data correctly, but when you try to save it ( using $save() ), data updates locally but fails to do so remotely.
Tested few theories, tried to call $firebase within controller, using something like:
$scope.fb = $firebase(new Firebase(_config.url+'/list/'))
$scope.fb.$on('loaded', function(d){
$scope.fb[$scope.fb.$getIndex()[0]].test = 'AAAAAA!'
$scope.fb.$save()
})
The above worked as should, so i assume it has something to do with promises.
Would anyone have any ideas?
EDIT ---
Still struggling to figure out the issue, but was able to narrow it down to resolve:
.when('/list/',{
controller : function(){
new Firebase('https://XXX.firebaseio.com/test/').push('Hey!');
},
templateUrl : 'template/list.stache',
resolve : {
list : function($q,$firebase){
var d = $q.defer(),
ref = new Firebase(_config.url+'/list/');
ref.once('value', function(s){
if(s.val() == null){
d.reject('Object not found');
}
d.resolve($firebase(ref));
});
return d.promise;
}
}
})
It fails. But :
.when('/list/',{
controller : function(){
new Firebase('https://XXX.firebaseio.com/test/').push('Hey!');
},
templateUrl : 'template/list.stache'
})
Works as expected.
Note that both approaches works fine in a browser ( tested on firefox and chrome ). It only fails when compiled to android app using phonegap.
Any ideas are appreciated.
I had the same thing. The connection is lost.
Use the function Firebase.goOffline(); and Firebase.goOnline();. This allows you to manually control the client connection.
Example:
var usersRef = new Firebase('https://samplechat.firebaseio-demo.com/users');
Firebase.goOffline(); // All Firebase instances are disconnected
Firebase.goOnline(); // All Firebase instances automatically reconnect
Link for reference
I'm not having much luck so far in loading the filepicker package in my Meteor project.
What I did:
$cd ~/myMeteorProject
$mrt add filepicker
>>>Done installing smart packages
$head smart.json
>>>{
"packages": {
"router": {},
"filepicker": {}
}
}
$mrt
>>>Stand back while Meteorite does its thing
Done installing smart packages
Ok, everything's ready. Here comes Meteor!
[[[[[ ~/myMeteorProject ]]]]]
=> Meteor server running on: http://localhost:3000/
So at this point all looks like I'd expect. ( I even double checked the contents of the filepicker package and it contains all of what i'd expect, the source to load has the same URL as is found on the filepicker.io site, etc.)
However, when I try to run the following (compiled from coffeescript):
if (Meteor.isClient) {
Meteor.startup(function() {
return filepicker.setKey('A9FiXXdu5RB^GYujfDPwlz'); //not my actual key, don't worry
});}
I get: Uncaught ReferenceError: filepicker is not defined
So, that's kind of a bummer. Any ideas? I've tried removing and re-adding both coffeescript and filepicker. is there some load-order issue? I note that filepicker-load.js has an alert if the script fails to load, which I'm not seeing...
I've had the exact same problem and for me, neither wrapping it in a setTimeout() nor a setInterval() worked.
Ink themselves provide a great non-blocking script in their docs, that queues all filepicker calls until its fully loaded and then executes them in the order they were called. This is how it works:
mrt remove filepicker (if added)
mrt remove loadpicker (if added)
create new file /lib/filepicker.js
/lib/filepicker.js
if (Meteor.isClient) {
(function(a) {
if (window.filepicker) {
return
}
var b = a.createElement("script");
b.type = "text/javascript";
b.async = !0;
b.src = ("https:" === a.location.protocol ? "https:" : "http:") + "//api.filepicker.io/v1/filepicker.js";
var c = a.getElementsByTagName("script")[0];
c.parentNode.insertBefore(b, c);
var d = {};
d._queue = [];
var e = "pick,pickMultiple,pickAndStore,read,write,writeUrl,export,convert,store,storeUrl,remove,stat,setKey,constructWidget,makeDropPane".split(",");
var f = function(a, b) {
return function() {
b.push([a, arguments])
}
};
for (var g = 0; g < e.length; g++) {
d[e[g]] = f(e[g], d._queue)
}
window.filepicker = d
})(document);
filepicker.setKey(YOUR_FILEPICKER_KEY);
}
This client code is a vanilla version of the non-blocking loader taken from https://developers.inkfilepicker.com/docs/web/. Using this, you can set the key once and then use filepicker as you like without worrying about if it's already loaded or not.
Of course you could also modify loadpicker with this, just paste in this code in your loadpicker.js
loadpicker.js
loadPicker = function(key) {
(function(a) {
if (window.filepicker) {
return
}
var b = a.createElement("script");
b.type = "text/javascript";
b.async = !0;
b.src = ("https:" === a.location.protocol ? "https:" : "http:") + "//api.filepicker.io/v1/filepicker.js";
var c = a.getElementsByTagName("script")[0];
c.parentNode.insertBefore(b, c);
var d = {};
d._queue = [];
var e = "pick,pickMultiple,pickAndStore,read,write,writeUrl,export,convert,store,storeUrl,remove,stat,setKey,constructWidget,makeDropPane".split(",");
var f = function(a, b) {
return function() {
b.push([a, arguments])
}
};
for (var g = 0; g < e.length; g++) {
d[e[g]] = f(e[g], d._queue)
}
window.filepicker = d
})(document);
filepicker.setKey(key)
};
Hope this works for you!
your syntax looks good and matches what i use in my app - i'm thinking that since filepicker loads the script by injecting a script element, you have a timing issue (calling setKey before the script is loaded)
maybe hold off on setting the key until the user does something, like
filepicker.setKey("KEY");
filepicker.pickAndStore({...},function(error){...});
or set it with a timeout
Meteor.setTimeout(function(){
filepicker.setKey("KEY");
},1000);
you could also use an interval to check if desired (more tolerant of long load times) - you could adjust this to give up after a certain amount of time
var filepickerInterval = Meteor.setInterval(function(){
if(filepicker){
Meteor.clearInterval(filepickerInterval);
filepicker.setKey("KEY");
}
}, 100);
You also can use the asynchronous javascript snippet to auto-queue calls to the filepicker object until the script loads. See https://developers.inkfilepicker.com/docs/web/#javascript
This is a function to add a dictionary as a subitem of a main document.
addSubItem = function(id, data) {
s = Item.findOne(id);
if(s){
Item.update({_id:id},{$push:{'subItemsList':data}});
}
};
I verify the data passed and are a valid main document id a subitem data.
data = {num:1, value: 'Subitem1'};
This works fine yesterday with the latest version of meteor (0.4.2), but today I get this message at javascript console:
Error: Cannot apply $push modifier to non-array
I created and setup a new project and I still get the same.
Thanks to Lloyd, Nice workaround and thanks for the javascript crash course (i'm a begginer on it), but I found the solution: (note the "$push")
addSubItem = function(id, data) {
s = Item.findOne(id);
if(s){
Item.update({_id:id},{"$push":{'subItemsList':data}});
}
};
try this:
addSubItem = function(id, data) {
s = Item.findOne(id);
if(s){
s.subItemsList = s.subItemsList || [];
s.subItemsList.push(data);
Item.update(id, s);
}
};