Using ydn-db inside a Firefox Jetpack add-on - ydn-db

Has anyone had success running ydn-db inside of a FF Jetpack add-on? I've got it partially working but am now stuck.
I'm using ydn.db-isw-sql-e-cur-qry-dev.js v1.03. I had to modify it to require Jetpack's indexeddb library, once I did that ydn's put and get methods seem to work fine. So, this works as expected:
var db = new ydn.db.Storage('test');
q = db.put({name: "store1", keyPath: "id"}, {id: "id1", value: "value1"});
q.done(function(x){ console.log("put done",x) });
q.fail(function(x){ console.log("put fail",x) });
var clog = function(r) { console.log(r.value); }
db.get("store1", "id1").done(clog);
However 'results' has 0 length below:
db.from('store1').list(100).done(
function(results){
console.log('done',results.length);
for(var i in results){
console.log(i,results[i].id);
}});
I've confirmed that the above works in Chrome and in FF in a regular web page.

When YDN-DB is not behaving expecting for simple cases, there may be other problem. Try running with logging before instantiating ydn.db.Storage as follow:
ydn.debug.log('ydn-db', 'finest')
This will log very noisy log message to console. You should get idea what is going wrong.

Related

RequireJs Google maps google is not define

I have a simple nodejs project that should load asynchronously the google maps api javascript, i followed this answer https://stackoverflow.com/a/15796543
and my app.js is like this:
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
methodOverride = require("method-override");
https = require("https");
requirejs = require('requirejs');
requirejs.config({
waitSeconds : 500,
isBuild: true,
paths : {
'async': 'node_modules/requirejs-plugins/src/async',
}
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride());
var router = express.Router();
router.get('/', function(req, res) {
res.send("Hello World!");
});
requirejs(["async!http://maps.google.com/maps/api/js?key=mykey&sensor=false"], function() {
console.log(google);
});
app.listen(3000, function() {
console.log("asd");
});
package.json:
{
"name": "rest-google-maps-api",
"version": "2.0.0",
"dependencies": {
"express": "^4.7.1",
"method-override": "^2.1.2",
"body-parser": "^1.5.1",
"requirejs": "2.3.3",
"requirejs-plugins": "1.0.2"
}
}
i've got always the same error:
ReferenceError: google is not defined
The main issue here is that you are trying to run in Node code that is really meant to be used in a browser.
The async plugin
This plugin needs to be able to add script elements to document and needs window. I see you set isBuild: true in your RequireJS configuration. It does silence the error that async immediately raises if you do not use this flag, but this is not a solution because:
isBuild is really meant to be set internally by RequireJS's optimizer (or any optimizer that is compatible with RequireJS), not manually like you are doing.
isBuild means to indicate to plugins that they are running as part of an optimization run. However, your code is using the plugin at run time rather than as part of an optimization. So setting isBuild: true is a lie and will result in undesirable behavior. The async plugin is written in such a way that it effectively does nothing if isBuild is true. Other plugins may crash.
Google's Map API
It also expects a browser environment. The very first line I see when I download its code is this:
window.google = window.google || {};
Later in the code there are references to window.document and window.postMessage.
I don't know if it is possible to run the code you've been trying to load from Google in Node. I suspect you'd most likely need something like jsdom to provide a browser-like environment to the API.
assuming you did everything else correctly, which I am not testing here. The reason you are getting the error is because you call console.log(google) and there is no google variable. You need to pass google in as a reference in your call back function. This will either get rid of the error, or change the error if you have set up requirejs incorrectly.
requirejs(["async!http://maps.google.com/maps/api/js?key=mykey&sensor=false"],
function( **google** ) {
console.log(google);
});
see the requirejs docs http://requirejs.org/docs/node.html#1

Firebase rules not working with code

I am not able to make the security rules in Firebase database working although the simulator shows they are in place.
A simple example:
{
"rules": {
"items":{
"$itemid":{
".read":true,
".write":"newData.child('id').isNumber()"
}
}
}
}
For above rules when I try posting an item from simulator with text value in 'id' it gives proper error as expected.
For Url: /items/-sdsd123
And for data: {"id":"MAC1", "name":"Macbook Pro"}
It gives write denied error in simulator as 'id' is not number.
However after publishing the rules and trying from code or browser data editor it allows the id to be text value. Below works:
var key = db.ref("/items").push().key;
db.ref('/items/' + key).set({"id":"MAC1", "name":"Macbook Pro"});
I am missing something basic but not able to figure it out, kindly help.

"callback is not a function" with $bindToContext

In my angular-meteor app I'm using mdg:camera. I'm trying to update a field from the callback to show the image. Here's the code snippet:
this.addImageToPost = () => {
MeteorCamera.getPicture({
quality: 50
}, this.$bindToContext((err, data) => {
if (err) {
console.log(err);
return;
}
this.imgDataUrl = data;
}));
};
This has been working great. But now after I finished updating my app to use meteor 1.3 (with all the new updates to angular package and mdg:camera as well) this became broken with a "callback is not a function" error.
If I remove the "this.$bindToContext" part, I get a working code - only obviously it's not reactive.
Any idea what's going on? I wonder if the newest updates broke something...
Any help would be greatly appreciated!

Meteor getting this.params._id undefined

UPDATE: I got the issue fixed, it was due to my Meteor Publish setting I had to change it to return Links.find(); and then filter the correct data in my links list return Links.find({topicId: this._id}, {sort:{submitted: -1}});
So I'm getting some very weird issue and I'm really stuck.
I have the following route setup
this.route('linkEdit', {
path: '/link/:_id/edit',
data: function() {
console.log(this.params);
console.log(this.params._id);
console.log(Links.findOne(this.params._id));
return Links.findOne(this.params._id)
}
});
So this.params is fine I'm getting - [_id: "LiAiifzPHmMR23tg3", hash: undefined]
For this.params._id - I'm getting the correct ID, LiAiifzPHmMR23tg3
But for Links.findOne(this.params._id) - I'm getting undefined
However when I check mongodb I have a link with that ID.
Also if I add an alert, while the alert is popping up the template renders the data but then re-renders and I'm getting blank data as it can't find the correct link ID.
That's because your collection query is a bit off, you'll want to change that to the following:
Links.findOne({_id: this.params._id});

firebase Not saving data

Im using firebase and for some reason my code is not pushing data and im not seeing the data in the firebase url. My code is this
var chatref = new Firebase('https://flockedin.firebaseio.com/');
chatref.push({ ChatId: $('#conversationId').text(), User: $('#username').html(), Message: $('#txtchat').val() }, function (response) { if (response) { alert('saved'); } });
i get the alert 'saved' but i cant find the data in firebase url.
Also what is the use of API Key that is given for each url in the firebase.
UPDATE:This happens in IE10. In other browsers it works fine
IE10 seems to be working for me. Can you give more details about what version you are using (desktop / tablet / phone?).
Also, is it possible that your jquery selectors were returning null? If all of the values in the object that you set evaluate to null, Firebase treats it like a call to remove. See the note in the docs for set: https://www.firebase.com/docs/javascript-client/firebase/set.html
Try going to your FireBase Console->Database->Rules and set them to:
{
"rules": {
".read": true,
".write": true
}
}
Make sure your app is not public when you do this. Lmk if it helps.

Resources