Move call to .bind behind a Turbolinks.supported check#284
Move call to .bind behind a Turbolinks.supported check#284packagethief merged 1 commit intoturbolinks:masterfrom
Conversation
|
Maybe this should short-circuit earlier, though? TL obviously isn't expected to work with IE8, so maybe it should shut off sooner. |
|
I agree, @nateberkopec. |
|
@nateberkopec The one other spot it could work is in the Controller class, where the ScrollManager is instantiated. There is a support check in the @packagethief Would that cause an issue with calling start/stop, since the instantiation would be in the start method? To clarify, though, are we talking about putting it in the |
|
@trueheart78, yes, I was suggesting we put it in ScrollManager's diff --git a/src/turbolinks/scroll_manager.coffee b/src/turbolinks/scroll_manager.coffee
index 1de743e..5368ee6 100644
--- a/src/turbolinks/scroll_manager.coffee
+++ b/src/turbolinks/scroll_manager.coffee
@@ -1,16 +1,16 @@
class Turbolinks.ScrollManager
constructor: (@delegate) ->
- @onScroll = Turbolinks.throttle(@onScroll).bind(this)
start: ->
unless @started
- addEventListener("scroll", @onScroll, false)
+ @throttledOnScroll ?= Turbolinks.throttle(@onScroll).bind(this)
+ addEventListener("scroll", @throttledOnScroll, false)
@onScroll()
@started = true
stop: ->
if @started
- removeEventListener("scroll", @onScroll, false)
+ removeEventListener("scroll", @throttledOnScroll, false)
@started = falseI bet @javan can think of a better way 😄 |
|
How about diff --git a/src/turbolinks/scroll_manager.coffee b/src/turbolinks/scroll_manager.coffee
index 1de743e..98e38d1 100644
--- a/src/turbolinks/scroll_manager.coffee
+++ b/src/turbolinks/scroll_manager.coffee
@@ -1,6 +1,6 @@
class Turbolinks.ScrollManager
constructor: (@delegate) ->
- @onScroll = Turbolinks.throttle(@onScroll).bind(this)
+ @onScroll = Turbolinks.throttle(@onScroll)
start: ->
unless @started
@@ -19,7 +19,7 @@ class Turbolinks.ScrollManager
scrollToPosition: ({x, y}) ->
window.scrollTo(x, y)
- onScroll: (event) ->
+ onScroll: (event) => |
|
Those both look like they would work. What should my next step be? Seeing commit hashes tells me you've both done some work. |
|
@trueheart78, I'd update this PR using @javan's suggestion (and confirm it works). Thank-you! |
|
I updated it with @javan's suggestion, and force pushed. All tests still pass. Will be testing it in IE8 shortly. |
|
IE8 is still working as-expected with the updated build. |
|
Thanks @trueheart78! |
|
Glad to help out, @packagethief @javan |
|
Hey @trueheart78, not a big deal, but for future reference you don't need to commit the compiled JavaScript in |
|
Thanks for the info, @packagethief. And thanks for the release. |

Internet Explorer 8 continued to raise an exception when attempting to use Turbolinks v5.0.2. We kept getting,
TypeError: Object doesn't support this property or methodfor.bind(), which is used only in the ScrollManager constructor. In this same browser,Turbolinks.supportedreturnsfalse, so this was not expected.This PR changes it to check that Turbolinks is supported prior to calling
.bind().Worked with @JakeTobin on this to verify the cause and that this change provides a fix.