redgeoff / delta-pouch

Conflict-free collaborative editing for PouchDB
196 stars 13 forks source link

Problem with delta-pouch updated document in AngularJs. #30

Closed alearcy closed 10 years ago

alearcy commented 10 years ago

Hi! I'm Italian developer. I'm using delta-pouch within Ionic Framework app (AngularJs). I posted a Stackoverflow answer here. I created a new territory object:

 var newTerritory = {
            name: territory.name,
            number: territory.number,
            owners: [ ]
        };
        pouch.save(newTerritory).then(function (doc) {
            console.log(doc);
        });
    };

and the console log response is:

id: "BAF60DA8-3880-18D3-82F2-592C771C0123"
ok: true
rev: "1-95b5a3ef53d414a65f824f5a7dd503de"

after that, I update the document with this code:

$scope.editTerritory = function(index){ 
            $scope.modalEdit.show(); //open form modal
            $scope.doEditTerritory=function(territory) { //modal pass territory object modified
                pouch.save({
                    $id: index.$id,
                    name: territory.name,
                    number: territory.number
                });
            };
        };

Now, instead of having the updated document, I have the old one and a completely new one without owners array field...

Did I do something wrong or it is a bug?

Thanks!

redgeoff commented 10 years ago

Hi @alearcy, I've added a little more documentation to the README that may help to explain how the plugin works. Also, I'd suggest taking a close look at the profile and websites examples.

If you are still experiencing problems after that then can you post your code somewhere and link to it here so that I can see what is going on behind the scenes?

Also, I'm finishing off some work on an angularjs binding for delta pouch that should make it very easy to use delta pouch. Please stay tuned!

alearcy commented 10 years ago

Thanks @redgeoff for your reply. I'm a little bit confuse :-D In the code posted before, I simply did a get to the doc, after created it with pouch.save, and then updated it with pouch.save (in my code pouch.save it's equal to your db.save). Correctly, delta-pouch create a new document, but the owners array inside it was deleted. Did I get doc with delta-pouch plugin method or can I get it with simple pouch.get (db.get)?

I can't share with you my code because it's a private project. IMHO, the problem is $id that isn't correctly create and then update it.. If this was your code, what would you do? if you can suggest me some solutions, it would be great, otherwise I will wait for your Angular adapter for test it.

alearcy commented 10 years ago

Hi @redgeoff, should I consider this issue unresolved? If not, I will waiting for your reply ;-)

redgeoff commented 10 years ago

@alearcy, I've released an all-in-one angularjs binding called factoryng that you can use to incorporate delta pouch (or vanilla pouch) into your angular code. Let me know what you think!

redgeoff commented 10 years ago

Closing as factoryng is the recommended way to use delta pouch with angular. Please open an issue at factoryng if you are still having problems.