Closed minicuper closed 10 years ago
Weird, it works on the heroku project now and I think I fixed this error, the heroku project might be outdated now though.
I'll take a look at it.
Maybe it's a kind of incompatibility... livedb-mongo: 0.2.5 racer: 0.5.11
Hi guys. @zag2art do you understand the code. I don't find it all too "self-explanatory". However it sure has potential.
What is the "all" event really all about? Is it a catch-all event? ie. an event generated and emitted by any mutator event?
#refList.mocha.coffee
model.on 'all', 'list**', (capture, method, index, values) ->
expect(capture).to.equal ''
expect(method).to.equal 'insert'
expect(index).to.equal 0
expect(values).to.eql [
Looks like much of this Racer API documentation must be gathered from the DerbyJS blog :o:
Wow, so difficult to track, unless you get very deep into all this and spend a lot of effort digging around in the ditches!
// This map determines which events get re-emitted as an 'all' event
// Model.MUTATOR_EVENTS = {
// change: true
// , insert: true
// , remove: true
// , move: true
// , stringInsert: true
// , stringRemove: true
// , load: true
// , unload: true
// };
// Model.prototype.on = function(type, pattern, cb) {
// var listener = eventListener(this, pattern, cb);
// this._on(type, listener);
// return listener;
// };
var racerPath = path ? path + '**' : '**';
model.on('all', racerPath, function () {
This is my current understanding of some of the core logic. You have to deep somewhat "deep" into the RacerJS API to understand what is really going on...
This piece I don't fully understand:
TodoCtrl.resolve = {
model: function (racer) {
return racer;
}
};
TodoCtrl.resolve.model.$inject = ['racer'];
Ah, ok, looks like Resolve is related to Angular Controllers and Routing?
http://stackoverflow.com/questions/14980805/angularjs-resolve-with-controller-as-string
And then there is the deferred promise resolve: def.resolve(model);
http://api.jquery.com/deferred.promise/
What is the function extendObject(from, to)
really doing? Is it just an internal version of deep-copy, ie. clone of any nested javascript Object? Could we just as well use similar functionality from an existing library such as Angular, jQuery etc? or does it require some special handling not mentioned?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor
I would really like to see this example extended to show how it would look for an example app with two models or more, perhaps using the typical Blog example, with Posts
and Comments
.
Does the model.get = function (path) {
receive any change from the server which must be updated (merged) on the client model?
I guess you have to debug this example app with a lot of console.logs
in order to have any understanding of what is going on behind the scenes and be able to expand on it beyond this "hello world" example.
# web.js
model.subscribe('entries', function (err, entries) {
if (err) {
res.status(500);
res.send(err);
} else {
model.bundle(function (err, bundle) {
res.send(JSON.stringify(bundle));
});
Looks like the example is heavily inspired by the todos
example app inside RacerJS racer/examples
folder.
Aha! Good to know. In there we can find perhaps find better/more comments for some understanding ;)
# server.coffee
model.query('todos', todoIds).subscribe (err) ->
return next err if err
# Create a two-way updated list with todos as items
list = model.refList '_page.list', 'todos', todoIds
# model.bundle waits for any pending model operations to complete and then
# returns the JSON data for initialization on the client
context = {list: list.get(), groupName}
model.bundle (err, bundle) ->
return next err if err
context.bundle = bundle
res.send templates.page(context)
Perhaps the above investigative "journalism" would help you @zag2art ?
Looking at the examples in Racer, the dependencies are:
"racer-browserchannel": "~0.1.0",
"livedb-mongo": "~0.1.2",
So this could clearly be an issue... ?
I would like to write a directive or similar library that can be inserted for any project, call it fx angular-racer which takes care of this plumbing and can easily be used (as an API) for more models. Then develop a racer adapter for Sails, very similar to the racer-db-mongo project at https://github.com/codeparty/racer-db-mongo
Any of you guys interested in such an approach?
Thanks!
Looks like much of this Racer API documentation must be gathered from the DerbyJS blog :o:
Yeah, sadly noone bothered to really write a documentation for bootstrapping racer itself; all the info I got was either from source or the derby docs.
What is the function extendObject(from, to) really doing? Is it just an internal version of deep-copy, ie. clone of any nested javascript Object?
Yes it is.
Could we just as well use similar functionality from an existing library such as Angular, jQuery etc?
Can't use angulars extend since it doesn't overwrite existing properties. I didn't want to introduce a dependency to jQuery, so no idea there.
Any of you guys interested in such an approach?
I'm probably not going to work on extending this myself. I just wanted to quickly demonstrate, that the derby "vendor lockin" isn't necessary to get the DB sync capabilities.
I am going to fix this bug though, even though I thought I fixed it with my last commit, but maybe a new version killed it again.
I tried to make the code more readable etc. You are welcome to fix whatever needs fixing in my code gist here ;)
Do the changes from https://github.com/codeparty/racer/pull/167 fix this error for you @zag2art?
trying this example-repo out and received this error. I unhooked the mongolab and redis cloud stuff and I'm using local versions of each. Mongodb 2.2.2 and redis 2.6.7
also confirming I added bulkSubscribe
and verified I'm on live-mongo-0.2.6
morgan@ubuntu:~/Documents/projects/racer-angular-example$ node app.js
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Trace: { [MongoError: Modifiers and non-modifiers cannot be mixed]
name: 'MongoError',
err: 'Modifiers and non-modifiers cannot be mixed',
code: 10154,
n: 0,
connectionId: 3,
ok: 1 }
at /home/morgan/Documents/projects/racer-angular-example/node_modules/racer/node_modules/share/lib/server/session.js:591:19
at /home/morgan/Documents/projects/racer-angular-example/node_modules/racer/node_modules/share/lib/server/useragent.js:294:23
at /home/morgan/Documents/projects/racer-angular-example/node_modules/racer/node_modules/share/node_modules/livedb/lib/index.js:514:31
at null.<anonymous> (/home/morgan/Documents/projects/racer-angular-example/node_modules/livedb-mongo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/collection.js:477:9)
at g (events.js:175:14)
at EventEmitter.emit (events.js:106:17)
at Server.Base._callHandler (/home/morgan/Documents/projects/racer-angular-example/node_modules/livedb-mongo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/base.js:130:25)
at /home/morgan/Documents/projects/racer-angular-example/node_modules/livedb-mongo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/server.js:522:20
at MongoReply.parseBody (/home/morgan/Documents/projects/racer-angular-example/node_modules/livedb-mongo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:132:5)
at null.<anonymous> (/home/morgan/Documents/projects/racer-angular-example/node_modules/livedb-mongo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/server.js:481:22)
kicked the tires some more and found that I can add an item to the todo and it works fine, though it doesn't display till I refresh the page. But then when I try to add an additional item to the todo list it throws the above error, but it does display the item in the html page. But when I refresh it disappears and I'm left with my first item only.
I was able to reproduce this first item works multiples don't by going into my mongod
db.entries.remove()
db.entries_op.remove()
Wow! The plot thickens. At least we are making some progress - it can run now :) Thanks! Just some more debugging remains...
Should be fixed by e182cab1c9d3569d35b394158fce3f06038bcbaf.
I also added a comment for localhost execution now - changing the mongod path is all that's needed.
The error is occurring while I am adding a todo.