Custom Events and Ajax Friendly Page-ready Checks

Originally published at: http://www.sitepoint.com/custom-events-ajax-friendly-page-ready-checks/

Not so long ago, I built a Chrome extension that lets users export lists from Trello. You can see the short series on how that was done here. That extension had some room left for improvements, though.

For example, checking whether the board has changed – something that’s less than simple to do considering all of Trello is ajaxy and the URL changes via undetectable pushstate. We also want it to support having multiple Trello tabs open, so just checking the URL wouldn’t do. It would also be good if we could somehow make sure slow page loads don’t affect the “page ready” state – in the original extension, due to Trello’s “over-ajaxness”, the page was “ready” before the content loaded – even the board’s area was loaded via ajax and as such, events weren’t easy to attach to the core DOM elements of Trello’s UI.

For that purpose, and to make my life developing extensions for Trello easier in the future, I decided to build a TrelloUI library which will take care of this particular issue for me. The TrelloUI library will be extended with other functionality in the future, but for now, let’s build our “ready checker”.

Continue reading this article on SitePoint

Nice article Bruno. I notice you changed the method name checkState to _checkState midway through the story. Perhaps you could explain your reasoning (for example, convention used for private methods)?

Oh snap, good catch, thanks! Fixed!

The method was supposed to be private all along, I just missed the underscore in the first code block. The underscore has always been an indicator of “privacy” in methods in various languages, so I used it here as convention. The checkState method isn’t meant to be used by anything outside this “library”, so marking it as private like so was only logical. It’s also a sort of precursor to a further upgrade to the whole matter of this extension - building React components to simplify Trello UI customization even further.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.