Skip to content

Updates to some WinJS helpers

by Brandon on March 14th, 2014

I’ve just posted important updates to two of my WinJS helpers.

Fix for dispose() in WinJS Control Template

The first is the WinJS Control template from my last post. I discovered a bug in the version I posted which prevents the dispose method from being called. This is because of some quirks to how the WinJS markDisposable and WinJS.Binding.Template code works. The fix I’ve implemented for now isn’t quite as pretty as I’d like, but it works well enough. I may look for a better option down the road, or feel free to suggest one!

For now, I fix it to ensure both versions are called via some simple monkey-patching. Here’s the relevant code snippet from the updated version of the template:


        this.initPromise = loadControlTemplate().then(function () {
            that.element.className = controlTemplate.element.className;
            // Unfortunately the template code ends up overriding our dispose method.
            // We'll monkey patch it here and ensure both are called.
            that._classDispose = that.dispose;
            return controlTemplate.render(options.dataSource, that.element).then(function (element) {
                that._templateDispose = that.dispose;
                that.dispose = function () {
                    this._classDispose();
                    this._templateDispose();
                };
                that._initialize();
                that.controlInitialized = true;
            });
        });

The result of this is that your dispose implementation (on the class) and that of the template both get called as expected.

Updated HttpClient wrapper

In my use of the HttpClient wrapper I posted a while back, I discovered a few problems and opportunities for improvements. This helper currently lives on GitHub in a Gist post, so you can see the changes I’ve made here.

One Comment

Trackbacks & Pingbacks

  1. Weekly Digest for Developers: Mar 09- Mar 16, 2014 | Super Dev Resources

Comments are closed.