Trouble implementing a Proxy

Hi,

I’m trying to implement a new proxy for PouchDB. The simplified code looks like this:

// Pouchdb (https://github.com/pouchdb/pouchdb) proxy
webix.proxy.pouchdb = {
  $proxy:true,
  load: function(view, callback) {
    var db = new PouchDB(this.source, config);
    var dp = webix.dp(view);
//    return db.get(view, callback);
  }
};

However, it fails on line 24610 of webix_debug.js (1.7.0), webix.DataProcessor._after_init_call():

this._settings.store.attachEvent(“onStoreUpdated”, webix.bind(this._onStoreUpdated, this));

undefined is not a function

It seems inside the DataProcessor, the store does not have an attachEvent() method. Actually, it only has a “driver” property. Shouldn’t it be a DataStore instance and have that method ? I need to get an id for the view in order to lookup on the database, and getting the DataProcessor seemed to be my choice, but I’m stuck.

Thanks,
Howe

If you need to get id - you can use
view.config.id, dataprocessor can be used if you want to handle data saving operations, but it is unnecessary for data loading.

  load: function(view, callback) {
    var db = new PouchDB(this.source, config);
    var doc = db.get(view.config.id, function(){
          view.parse(doc.data); //load data in component
    });
  }

Hello maksim,

I was aware of view.config.id, but that’s “$form1”. I think I’d need to access the serialized data from the form (actually, It’s just a login form and I need to match its only two fields: login and password).
I’ve tried view.serialize() as well, but that function isn’t defined… how can I access the view data, and customize serializing so that {“login”: “xxxx”, password: “yyyyy”} gets mapped to {"_id": “xxxx”, password: “yyyyy”} as pouchdb expects me to search ?

Thanks!
Howe

you can use view.getValues() - it will return json object with all data from the form.

As for customization - you can use custom code to update json object, or just use name:"_id" for the login field in the form. In such case form will return value in the way necessary for PouchDB

Hello maksim,

I had the same problem while using the webix:webix package. The error occured upon view update (after DB change).

Stack:

Exception in queued task: TypeError: this._settings.store.attachEvent is not a function
at Object.webix.DataProcessor.webix.proto._after_init_call (http://localhost:3000/packages/webix_webix.js?4da16d463223c73cab897d8cf6d4284ded156c15:28509:24)
at Object.webix.proto.result (http://localhost:3000/packages/webix_webix.js?4da16d463223c73cab897d8cf6d4284ded156c15:261:19)
at Object.webix.dp (http://localhost:3000/packages/webix_webix.js?4da16d463223c73cab897d8cf6d4284ded156c15:28438:11)
at Object.webix.proxy.meteor.load.query.cursor.observe.changed (http://localhost:3000/packages/webix_webix.js?4da16d463223c73cab897d8cf6d4284ded156c15:31730:11)
at LocalCollection._observeFromObserveChanges.observeChangesCallbacks.changed (http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:3928:28)
at Object.LocalCollection._CachingChangeObserver.self.applyChange.changed (http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:3832:44)
at http://localhost:3000/packages/minimongo.js?af9eb9d7447544ca9b839a3dcf7ed2da2209b56c:415:13
at _.extend.runTask (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:693:11)
at _.extend.flush (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:721:10)
at _.extend.drain (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:729:12)

Thank you for your time.

Can you share code, that was used for data loading and data saving initialization? Have you used only “url” without “save” parameter?

Hi maksim,

Once again, thank you for your time. I have the same error with or without the ‘save’ parameter. At the moment I do not use save, as I implement my own form save function:

{ view: ‘button’,
label: ‘Save’,
type: ‘form’,
click: function(){
var form = this.getFormView();
var v = form.getValues();
Meteor.call(‘updateUser’, {
name: v.name,
surname: v.surname
});
}

This works. It does update the Meteor MongoDB. But if I change the MongoDB manually via a shell, the expected on my view does not happen but does get triggered, because I get that error (TypeError: this._settings.store.attachEvent is not a function).

My webix view is defined as follows (I use … for ommiting unecessary code):

{
view: ‘form’,
url: webix.proxy(‘meteor’, Meteor.users),
elements: [
{ id: ‘_id’, view: ‘text’, name: ‘_id’, label: ‘ID’, …},
{ id: ‘name’, view: ‘text’, …},
{ id: ‘surname’, …},
{
view: ‘button’,
label: ‘Save’,
type: ‘form’,
click: function(){ … }
}
}

( the expected ‘change’ I meant to write there, sorry )

… and yes, that was used for data loading (works) …

Hi,
anybody has a working proxy for pouchDB or can me point into the right direction?

Thanks,
Martin