Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Debounce paging #178

Closed
wants to merge 3 commits into from

Conversation

EWhite613
Copy link
Contributor

This project uses semver, please check the scope of this pr:

  • #none# - documentation fixes and/or test additions
  • #patch# - backwards-compatible bug fix
  • #minor# - adding functionality in a backwards-compatible manner
  • #major# - incompatible API change

demo-debounce

CHANGELOG

  • Add feature to debounce paging action (while maintaining page number)

@@ -0,0 +1,80 @@
/**
* TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got missed

@notmessenger
Copy link
Contributor

@EWhite613 was ember-concurrency considered for usage, as it would be the preferred implementation for this feature? If so, why was it not able to be used?

@notmessenger
Copy link
Contributor

This behavior is not a true debouncer, though it exhibits some behaviors of one. A debouncer limits the rate at which a function can fire. Attaching a debouncer to the window resize event is a good example where you can have multiple inputs actions/events but only want one execution to occur. In the logic you have put forward we are debouncing in the sense that we are not going to fire off intermediate data requests for each data page HOWEVER we then jump the user forward as many data pages as they have queued up so we are executing part of the logic more than once (data page selection vs actual retrieval).

The point: 1) we may wish to use a more accurate term and/or describe this behavior more accurately, and 2) this seems like it would be a jarring experience for the user. Especially as they click the next page and are waiting for results, don't get any, and then start clicking a bunch wondering what is broken/going on. If the interval value is kept to a low number though it will likely lessen this occurrence but if that is how this is intended to be mitigated this guidance should be conveyed in the documentation.

let newPage = currentPage + counter
newPage = newPage < 0 ? 0 : newPage
newPage = newPage > totalPages ? totalPages : newPage
this.set('_debouncedPaging', run.debounce(this, this._sendDebounceOnChange, newPage, debounceInterval))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple this.set() calls should be combined into a single this.setProperties() call.

const totalPages = this.get('_lastPage')
let counter = this.get('pageClickCounter') || 0
const isGoingBack = currentPage > page
isGoingBack ? counter-- : counter++
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to see these two lines combined as:

(currentPage > page) ? counter-- : counter++

If the const was used to provide context to the logic then a comment is preferred instead of a construct.

this._sendDebounceOnChange(page)
} else {
const totalPages = this.get('_lastPage')
let counter = this.get('pageClickCounter') || 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this.getWithDefault('pageClickCounter', 0) instead.

Line 36 has set _pageClickCounter to 0 but then it is never used in the code anywhere. I'm guessing that it should have not had an underscore and then it's value would have been what was expected here and having to default it to 0 wouldn't even be necessary?

export default Component.extend({

// == Dependencies ==========================================================

layout,

// == Properties ============================================================

_pageClickCounter: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never used anywhere. See https://github.com/ciena-frost/ember-frost-list/pull/178/files#r168236617 and the either refactor or remove.

},

onPaginationChange (page) {
this.get('notifications').success(`recieved action with page ${page}`, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change recieved to received

@EWhite613
Copy link
Contributor Author

Looking into different approach

@EWhite613 EWhite613 closed this Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants