-
Notifications
You must be signed in to change notification settings - Fork 64
state object information is inconsistent when adding/removing a model #13
Comments
Hi! Thanks for the suggestion. I do realize that I didn't update the state when adding and removing models, that is mainly because I just don't know what behavior is desirable under what circumstances. Perhaps you can help me by laying out a couple concrete use cases and what the behavior you think should be? Specifically, I'd like to see how you sync with the server before and/or after an add and/or remove operation. |
Thanks for the reply. Let me clarify that I'm working only on client mode, so no experience when server mode behavior. After rethinking the behaviour, I think it should be behave in client mode: Add use case
Remove use case
Those changes imply that some of the checks being done at _checkState are not valid anymore. What do you think ? Did I forget any use case ? Regarding the server mode, I guess you can follow the same logic. If it is a page collection add/remove operation, leave it unchanged (I mean remove or add the element but do not fetch updated page from server) and only fetch new data when navigating to other pages. And leave the remove/add call to server to happen only if the developer calls .save() in the page collection. Regarding the full collection, I guess it is not relevant in server mode, Am I wrong ? |
I'll make a commit later for this issue. Thanks! |
Here are my comments: (1) I don't think I have an answer for that, my user can do as many as he wants. I don't support right now paging in the server and I don't have a need for that (at least now). Another reason is that my client collections sometimes reach 50 elements, so I don't think it is a good idea to fetch the whole collection again. (2) Yes, I saw it is implemented in _onFullCollectionEvent and _onPageableCollectionEvent. Looks good. Agreed on (3) Not sure if that was clear, but that is done only in case we added the element to the full collection and it creates a new page. I added it so that it will behave similar to remove. But thinking again you are right. If currentPage is valid, we shouldn't change it. That must be the role and won't create some unexpected behaviour. (4) Yes, you are right, in case there are no record, my view should check and not render the pagination tab (render a empty message instead). In this case, it doesn't matter what is the totalPages. Thanks for preparing a commit. I will check it when it is ready. Let me know if you need any help. |
I've decided to set |
Looks sensible. But I have checked the new version and it is failing one of my tests - When removing the last element from the page collection, I get the exception Another issue is that it seems to me that the condition Can you please check ? |
I didn't end up using your tests for See https://github.com/wyuenho/backbone-pageable/blob/master/test/client-pageable.js#L202. |
No problem about the tests. The test I mentioned was a test I created for my application and not the one at fork. Regarding the first issue, my scenario is a full collection with 9 totalRecords, and pageSize as 4. I call |
@alanrubin Give 0.9.13 a whirl and see if it behaves saner for you. |
That did the job. Thanks ! |
Hey @alanrubin I'm preparing to release 1.0. Is there anything you'd like me to change/add before I release it? |
Hi, I think I have detected another bug: When reseting the fullCollection with new models, the "state" (most specifically the totalRecords) are updated after the pageableCollection is reseted (backbone-pageable line 475-477). In my case, the scenario is the following: If I have a pagination Backbone.View (renders the pagination controls for navigating - forward, back, pages number) listening to the "reset" event in the pageableCollection, it will be rendered with the previous state when a reset is done. That could be true for the event "remove" as well, but I still have to check that. My fix was: if (event == "reset" || event == "sort") {
options = collection;
state.totalRecords = this.models.length;
pageableCollection.state = pageableCollection._checkState(state);
resetQuickly(pageableCollection, this.models.slice(pageStart, pageEnd),
options);
} What do you think ? |
Another thing: In case you are interested, I have extended the pageable collection with methods similar to backbone.paginator, so I can use it straightforward with code already written for it. It includes filtering, sorting and some small behaviour changes to the library. Check it out, could give you some inspiration :) https://gist.github.com/4548113 |
@alanrubin can you open a new bug with a failing test case? |
I will open a new bug... But it will take some time to write the test - sorry no qunit experience, only jasmine. Will try to write the test tomorrow. |
doesn't have to be a real qunit test case, just a code snippet with some comment on your expectations will do |
Hi @wyuenho ,
First thanks for this great library. I'm trying to replace Backbone-paginator for a more stable library and found yours really good (and tested!).
I think I found a bug when adding/removing a model in the "client" mode. The status object is not consistent regarding the totalRecords and totalPages, and is not adjusted accordingly.
Additionally, when removing the last record of a page, the state continues to indicate that lastPage/currentPage is the empty page - I think behaviour should be that the empty page is automatically removed and the paginated collection points now to the lastPage-1 as the currentPage. The only exception should be when removing all the models from the collection - I think in this case I think totalPages and currentPage should be 1 (never 0 so not to break behaviour of the library).
I have committed to my fork tests for those issues (branch change_col_bug - alanrubin@f44b5fd). What do you think ?
I may have some time tomorrow to try to generate a fix for it.
Thanks,
Alan
The text was updated successfully, but these errors were encountered: