-
Notifications
You must be signed in to change notification settings - Fork 152
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
fix bid dropdown dismissal #1230
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ defer, extend, before } = require 'underscore' | ||
{ defer, extend, before, isEqual } = require 'underscore' | ||
Backbone = require 'backbone' | ||
{ AUCTION, CURRENT_USER } = require('sharify').data | ||
Form = require '../../../../components/form/index.coffee' | ||
|
@@ -11,6 +11,9 @@ helpers = require './helpers.coffee' | |
metaphysics = require '../../../../../lib/metaphysics.coffee' | ||
template = -> require('./templates/index.jade') arguments... | ||
|
||
LOT_STANDING_MAX_POLLS = 10 | ||
LOT_STANDING_POLL_INTERVAL = 1000 | ||
|
||
module.exports = class ArtworkAuctionView extends Backbone.View | ||
className: 'artwork-auction' | ||
|
||
|
@@ -23,7 +26,9 @@ module.exports = class ArtworkAuctionView extends Backbone.View | |
'change .js-artwork-auction-max-bid': 'setMaxBid' | ||
|
||
initialize: ({ @data }) -> # | ||
setInterval before(10, @updateBidLabel), 1000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to change this pattern, because the way it was before, the timer keeps on firing. It's better to clean up after ourselves by scheduling only the number of calls we want to make, rather than squelch the function calls beyond the ones we want. |
||
# Defer until next tick. This really just gets the sequence right for | ||
# testing to work. This doesn't feel like a great justification, though. | ||
setTimeout (=> @updateBidLabel LOT_STANDING_MAX_POLLS), 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The before hook in the tests uses a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should get you what you need: https://github.com/artsy/force/blob/master/desktop/apps/artwork/client/test/index.coffee#L18 -- There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, so maybe if I add |
||
|
||
openBuyersPremium: (e) -> | ||
e.preventDefault() | ||
|
@@ -102,7 +107,7 @@ module.exports = class ArtworkAuctionView extends Backbone.View | |
@$('.js-artwork-auction-bid-button') | ||
.text "Bid #{$(e.target).find('option:selected').attr 'data-display'}" | ||
|
||
updateBidLabel: => | ||
updateBidLabel: (remaining) -> | ||
metaphysics | ||
query: """ | ||
query artwork($id: String!, $sale_id: String!) { | ||
|
@@ -125,7 +130,15 @@ module.exports = class ArtworkAuctionView extends Backbone.View | |
variables: id: AUCTION.artwork_id, sale_id: AUCTION.id | ||
req: user: CURRENT_USER | ||
.then (data) => | ||
old_data = @data | ||
@data = extend data, user: CURRENT_USER? | ||
@render() | ||
|
||
@render() unless isEqual(old_data, data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently |
||
|
||
@delayedUpdateBidLabel(remaining - 1) if remaining > 0 | ||
|
||
.catch console.error.bind console | ||
|
||
delayedUpdateBidLabel: (remaining) -> | ||
setTimeout (=> @updateBidLabel remaining), LOT_STANDING_POLL_INTERVAL | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My version of the Damassi Transform is giving names to magic numbers 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is definitely clearer 👍