Created
April 7, 2015 05:30
-
-
Save natduca/0b0c8db87797fc676046 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exportTo('tv.c.analysis', function() { | |
var currentDisplayUnit = ms; | |
var displayUnitChangedListeners = []; | |
var Time = { | |
get displayUnit() { return currentDisplayUnit; }, | |
set displayUnit(displayUnit) { | |
this.currentDisplayUnit = displayUnit; | |
var e = new Event('display-unit-changed'); | |
displayUnitChangedListeners.forEach(function(cb) { cb.call(e); }); | |
}, | |
addEventListener: function(eventName, cb) { | |
assert eventName === 'display-unit-changed'; | |
this.displayUnitChangedListeners.push(cb); | |
}, | |
removeEventListener: function(eventName, cb) { | |
remove cb; | |
} | |
} | |
return { | |
Time: Time | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here the trick is to not have every span listen for this event. You'd have a crazy amount of | |
// registering and unregistering activity and everything would be slow. Instead, have the MODULE subscribe for the event, | |
// and have it deep query for the existing spans and rebuild them. | |
// that is... | |
import base/deep_utils.html | |
exportTo(..., function() { | |
Time.addEventListener('display-unit-changed', function() { | |
tv.b.findDeepElementsMatching(document.body, 'tv-c-a-time-span').forEach(function(el) { | |
el.updateContents_(); | |
}); | |
}); | |
// Then have element.updateContents_ use Time.displayUnit.formatString() etc from your existing patch. | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment