Backbone.js: "Remove nonexistent models if appropriate" fails - javascript

I don't know how to ask this but I'll try to be as specific and as comprehensible as I can.
I am working on application based on Backbone and Marionette which is fetching data from back-end api server. We have got some input field with auto-completion which works fine but just first time. Second time I'd type something the auto-complete crashes. Ehm, not exactly the auto-complete but the backbone.js itself. I am getting this error:
Uncaught TypeError: Cannot read property 'cid' of undefined backbone.js:716
_.extend.set backbone.js:716
Backbone.Collection.set backbone-relational.js:1851
_.extend.fetch.options.success backbone.js:860
Backbone.Paginator.Paginator.requestPager.Backbone.Collection.extend.sync.queryOptions.success backbone.paginator.js:840
jQuery.Callbacks.fire jquery.js:3073
jQuery.Callbacks.self.fireWith jquery.js:3185
done jquery.js:8251
jQuery.ajaxTransport.send.callback jquery.js:8598
Probably between two calls to retrieving data from api server I somewhere forget to "reset" retrieved model collection - I am very new to Backbone development so it is really possible.
I am sorry for not providing code samples but I want you to ask also something else - it is about how Backbone algorithm for "Remove nonexistent models if appropriate" works - can be found here https://github.com/jashkenas/backbone/blob/master/backbone.js#L734
I was curious why my code crashes so I started to debugging backbone script itself (maybe not so good idea as it looks but I found out something interesting). In the provided link above you can see that backbone is iterating through models and deletes everything that is not needed. Its O.K. but I think that there is bug because backbone tries to iterate N times where N is this.length instead of this.models.length. In my case this two lengths are different. In my models I have for example 2 models but backbone tries to iterate 4 times because the value of this.length is 4.
Could please anybody explain to me why are these values different? I assume that this.length should be updated any time the length of this.models changes but in my case this is not happening.
Any ideas?

If you're doing a collection.fetch() somewhere try replacing it with collection.fetch({reset: true}) - it worked for me.

Related

A clarification on Google Firestore query pagination

I am currently struggling in understanding how to paginate a firestore collection.
Say I have a collection with 10 docs and I have stored doc5 in my vue.js-based app.
If I wanted to fetch doc6 and doc7, I would issue the following pseudo-command:
query.startAt(doc5).limit(2).get().then(snapshot => ...)
What If I wanted to go two docs backwards relative to doc5? My first guess was to issue the following pseudo-command:
query.endBefore(doc5).limit(2).get().then(snapshot => ...)
Unfortunately, my guess is not correct. I actually obtain doc1 and doc2. This thing is driving me nuts. It is quite evident that I didn't understand the logic behind endBefore(). I did read the firebase docs but couldn't find any light.
May I ask for your merciful help?
If needed, I can provide more context... I am trying to isolate the issue and be as clear as possible.

XPages: How to fetch documents in view and read values?

I am a beginner with XPages, and I have looked at the TLCC Intro free training. I have also seen tutorials here. I have no experience with Lotus Notes, XPages or flat-structured databases. But, I do have some experience in JavaScript and good experience (IMO) in Java and Android.
I am facing the following problems.
1) I am trying to implement a very basic login mechanism.
Currently, I add users manually, based on a form. Now, I want to create a login page. I take a user and a password, and click on a button.
In the button, I want to read all documents associated with a view (that displays all usernames/passwords), compare with entered value, and if it exists check if the password fields match too.
Can someone please guide me in the correct direction? I can't figure out which functions to use. Also, should I be using Scope Variables? Is there a good document/tutorial regarding that?
I have tried the "view.getAllEntries()" method but it always returns null.
Am I approaching this correctly? Are there in-depth tutorials that can help me with this?
2) What is the method to debug SSJS? I am currently putting everything in a try/catch and printing the error there.
I apologize if this question has been asked elsewhere, I haven't really found anything regarding this. Please point me if there is this is a duplicate.
1.
Use view.getDocumentByKey(theUserName) to find a user document in your view. It returns the user document as NotesDocument or null if user is not in view. The view has to have a first sorted column with the usernamens.
2.
As of Notes Domino version 9 you can debug SSJS.

Nodejs - extend command doesn't work as expected

I've encountered a weird situation, I've been using the extend library and the _.extend command from underscore, in the following way:
var extended = extend({}, objA, objB);
I get only properties from one of the objects in the result, is there anything about extend that might be preventing it from getting all the properties from both objects?
I've used this pattern everywhere and it seemed to work as expected so far. Both are plain objects, not arrays or functions.
EDIT: I tried to make a demo, but it seems to work with both jQuery and Underscore - http://jsfiddle.net/x4UHQ/2/
While making the demo (from the objects I printed in my logs), I noticed one that when printed in console.log didn't appear as a string - it's a mongoose type of ObjectId, maybe that's somehow causing the problem? (that specific field exists in the output object, so I don't know)
UPDATE: this was the solution - UnderscoreJS wont extend object (add a lean option to the mongoose query - because that's somehow makes the object incompatible with underscore.
Sorry for new response, it better fits as comments for Madd0g response (but i don't have required reputation points for it).
You are right, it is fault of mongoose object, {lean: true} is one option to fix it, other options is calling mongooseObj.field.toJSON() - in some case it is more convenient method. For example if you have user object in controller (from auth middleware), and you need to transform some fields, then you don't need to refetch model from db.
So the problem was that one of the objects was an object from the mongoose library, it made extend commands break, the fix was to get the db object from mongoose with the lean option.
something like personModel.find({fname: "Joe"}, null, { lean: true })

Knockout cyclic error - need advice on finding the cause

I'm working on a large project with many developers. We have 2 pages using knockout that have been working for a while now. Some new, unrelated code was introduced and come to find out the 2 pages with Knockout no longer work properly. When the pages load, there's an error thrown like below. A little investigating lead me to think there's some kind parsing issue going on in the data-bind attributes. I've tried many things to get it working, but I keep getting the entire view model object returned whenever I try to access an observable property. I think this is what's causing the error I'm seeing below after the page loads.
It's very difficult for me to put examples in here so what I'm looking for is any advice on finding errors JavaScript and/or HTML mark-up that might be causing Knockout to fail.
<error>
(anonymous function)
r.Oa.v
r.i.q
r.a.n
e
h
f
r.R.fn.notifySubscribers
r.a.n
r.R.fn.notifySubscribers
r.w.b.G
b
Array.indexOf
r.a.k
r.T.Ha
b
PriceFormatted.ko.dependentObservable.read
h
f
r.R.fn.notifySubscribers
r.a.n
r.R.fn.notifySubscribers
r.w.b.G
b
Array.indexOf
r.a.k
r.T.Ha
b
// it keeps going from here...
Just wanted to update the answer for this. Unfortunately I didn't track down exactly what the issue was, but it had to do with rearranging the order of referenced script files in the Master page of the app. I reverted back to the original order and the issue went away so it's in fact related to a bigger issue of poorly written custom JavaScript throughout the app.

ExtJS 4 Problem with MVC concept

i'm trying to use the new MVC concept and therefore started witht the AccountManager Example (examples/simple). Everything works fine as far as I stick to the tutorial, but I tried to extend it a bit.
I define a border layout in 'Viewport.js' and assign a header component (views/Header.js) to 'north'
and a tab-Panel (views/MainPanel.js) which contains the 'views/user/List.js' as a tab.
Until now everything is ok.
But now i added another store (Profiles.js) and model (Profile.js),
changed the references in code to use profile-store instead of user-store.
I also updated the column-definition, imports ('requires') and everything es that is relevant(at least i think so...).
When i run my app i get a js-error in Observable.js -> addManagedListener-> 'item is undefined' when he tries to invoce the on-method of 'item'.
At first i tried hard to find the mistake i made in the code but I could not find anything,
so i started to play around a little bit and found out,
that it works as soon as I rename the folder 'user' in views/ to 'profile' (of course i had to fix some references in code too).
Is this behavior a bug or is it volitional?
If so can anybody please tell me how this is exactly working?
Thank you very much!
ExtJS looks for the Javascript files based on your model/view/controller declarations.
i.e. if in your tell your controller that you have a store called Profile (via the stores attribute) by default, it is going to look for a file at app_name/stores/Profile.js
The problem was that i had to give my controller a reference to the store and the model.
I didn't do that from the beginning, after my controller had a reference to the view, the view had a reference to the store and the store had a reference to the model.
So I assumed everything is ok.
But it seems to be mandatory to provide this information redundant as far as understand and i can live with that...

Categories

Resources