Skip to content

Allow non-pjax page updates.#684

Open
ndelage wants to merge 12 commits into
twbs:masterfrom
ndelage:extract-transitions
Open

Allow non-pjax page updates.#684
ndelage wants to merge 12 commits into
twbs:masterfrom
ndelage:extract-transitions

Conversation

@ndelage

@ndelage ndelage commented Oct 1, 2014

Copy link
Copy Markdown

Extract transition functionality from push.js into a new file, transitions.js.
Expose a global function, similar to PUSH named TRANSITION used to transition
from one page/view to another without dictating how the new markup is sourced.

This allows for Ratchet style page transitions when rendering client side.

I'll add comments to the diff shortly, highlighting some of the changes I've made.

Comment thread js/transitions.js

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I didn't see any reason to keep the list of bar element selectors in an object (see the key/value pairs at the top of push.js). So it's a simple list of selectors now.

@cvrebert

cvrebert commented Oct 4, 2014

Copy link
Copy Markdown
Contributor

@ndelage This is failing in Travis: https://travis-ci.org/twbs/ratchet/builds/36779341

@ndelage

ndelage commented Oct 4, 2014

Copy link
Copy Markdown
Author

Yeah, I noticed. The linter doesn't think TRANSITION has been defined. But in the context of a full Ratchet codebase, it is defined on window (as part of transitions.js). I haven't put too much effort into satisfying the linter yet. I figure we can cross that bridge once we've discussed the patch.

I'm welcome to any suggestions if you've dealt with a similar issue before.

@hnrch02

hnrch02 commented Oct 4, 2014

Copy link
Copy Markdown
Contributor

Change /* global _gaq: true */ to /* global _gaq, TRANSITION */ to fix that.

@ndelage ndelage force-pushed the extract-transitions branch from 5b441a9 to 51ccdf4 Compare October 10, 2014 16:44
@ndelage

ndelage commented Oct 10, 2014

Copy link
Copy Markdown
Author

Thanks, Travis is passing now.

Comment thread js/transitions.js Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@ndelage Suggest to modify this line as follows:

document.body.innerHTML = "";
document.body.appendChild( contents );

This will ensure that all bound events and data will remain attached to the element instead of "flattening" it to just HTML string

@ndelage

ndelage commented Oct 12, 2014

Copy link
Copy Markdown
Author

Thanks for the comments @avinoamr, these are spot on. I agree with moving TRANSITIONto PUSH. I wasn't too excited to expose another global. That said, it seems that Ratchet would benefit from a single namespace, but that's another discussion entirely.

I'll submit the relevant changes in the next day or so.

Comment thread js/transitions.js Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@ndelage If transition is set, you end up calling complete() twice - once here and again when the transition completes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've removed the premature (before the transition completes) call to complete. In my version transitionContent is only called when a transition is present.

@ndelage

ndelage commented Oct 13, 2014

Copy link
Copy Markdown
Author

Now appending content instead setting innerHTML.

@ndelage ndelage force-pushed the extract-transitions branch from f31fe28 to 1637b4f Compare October 13, 2014 02:51
@hnrch02

hnrch02 commented Oct 22, 2014

Copy link
Copy Markdown
Contributor

Pinging @connor for a review.

@ndelage

ndelage commented Oct 22, 2014

Copy link
Copy Markdown
Author

I'd love some feedback, but given the potential that we move to a module approach with a single top-level object/namspace Ratchet, I think it makes sense to move the new TRANSITION function into the push.js IIFE. This way we avoid adding another global.

Later if we move towards a single Ratchet object, it will be easy to expose the transition functionality via a property of Ratchet (e.g. Ratchet.transition)

@Tarang

Tarang commented Oct 26, 2014

Copy link
Copy Markdown

Cool PR. It would definitely help our project. I've not dived deep in, but is it able to take DOM over raw html?

@ndelage

ndelage commented Oct 26, 2014

Copy link
Copy Markdown
Author

Yep, that's the idea. The TRANSITION function takes the markup & transition style as arguments. I've been using this with a Backbone app (allowing me to avoid PJAX)

@Tarang

Tarang commented Oct 27, 2014

Copy link
Copy Markdown

Cool! I just gave this ago but I seem to have a couple of problems. I tried to use TRANSITION(domElement, 'slide-out') or slide-in. If I remove the transition it swaps the page out. With the transition I can see the transition going on, but the new page seems to disappear and I'm remaining with the old page, albeit without the titlebar.

@ndelage

ndelage commented Nov 8, 2014

Copy link
Copy Markdown
Author

Hey @Tarang, sorry for the delay. I just pushed an update, including auto-generated js & css in dist/. The update allows for both HTML markup as a string or DOM elements as the contents argument to TRANSITION. Here's example usage, passing a string:

var contents =   "<div><div class='bar-tab'></div><div class='bar-nav'></div><div class='contents'<p>Foo Bar Baz</p></div></div>";
TRANSITION(contents, 'slide-left');

The single wrapper <div> needs to be included. It could be another element (like <body>) if necessary. But the contents argument needs to represent a single element.

Give it another shot and let me know if you run into any issues.

@yenbuilds

Copy link
Copy Markdown

Is anybody else noticing a memory leak on transitions?

@ndelage

ndelage commented Nov 8, 2014

Copy link
Copy Markdown
Author

Could you test master for the same leak? Can you provide details on how you've been testing for memory leaks?

@ndelage

ndelage commented Nov 8, 2014

Copy link
Copy Markdown
Author

Just added a step to clone the contents argument to TRANSITION (I discovered it was being modified when applying a transition).

@ndelage

ndelage commented Nov 8, 2014

Copy link
Copy Markdown
Author

Disclaimer: I'm no expert in tracking down memory leaks or profiling JS. I ran some tests using Chrome's timeline, tracking memory usage over time and forcing garbage collection a few times throughout the test. After each GC, it looks like everything has been cleaned up. I don't see a memory increase:

garbage-collection

@yenbuilds

Copy link
Copy Markdown

Thanks Nate for the reply! I looked deeper into it and it seems like it may be a weird jQuery XHR issue, and not related to the TRANSITION call. I also looked at the DOM through the remote Safari debugger and it looks like everything is being cleaned up correctly. So sorry about that.

@ndelage ndelage force-pushed the extract-transitions branch from a4c77f5 to f95101c Compare November 9, 2014 22:37
@cocoademon

Copy link
Copy Markdown

Is this likely to be merged?
I'd love to switch from using my current workaround, which is having a bunch of empty .html and injecting template contents in an on('push') handler.

@XhmikosR

XhmikosR commented Feb 4, 2015

Copy link
Copy Markdown
Member

@ndelage: can you rebase and clean up this branch?

@luisrudge

Copy link
Copy Markdown

+11111111 to this :)

@XhmikosR

XhmikosR commented Feb 9, 2015

Copy link
Copy Markdown
Member

@ndelage: please fetch and rebase.

@ndelage

ndelage commented Feb 9, 2015

Copy link
Copy Markdown
Author

Will do. I'll get to this in the next few days.

ndelage added 10 commits March 12, 2015 09:42
Extract transition functionality from push.js into a new file, transitions.js.
Expose a global function, similar to PUSH named TRANSITION used to transition
from one page/view to another without dictating how the new markup is sourced.

This allows for Ratchet style page transitions when rendering client side.
Ensure that all bound events and data will remain attached to the
element instead of "flattening" it to just HTML string.
@ndelage ndelage force-pushed the extract-transitions branch from f95101c to 0961870 Compare March 12, 2015 14:50
@ndelage

ndelage commented Mar 12, 2015

Copy link
Copy Markdown
Author

Just pushed a rebased branch, switching over to the new window.RATCHET global. Going to do a bit of testing locally, but feel free to have another look at the pr.

@XhmikosR

Copy link
Copy Markdown
Member
  1. We don't need the dist files in the PR to reduce conflicts
  2. Many of the patches can be squashed

@ndelage

ndelage commented Mar 12, 2015

Copy link
Copy Markdown
Author

Roger. I'll make those changes.

@qkdreyer

Copy link
Copy Markdown

Any updates ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants