Closed Bug 833011 Opened 13 years ago Closed 9 years ago

window/utils doesn't replicate WindowTracker

Categories

(Add-on SDK Graveyard :: General, defect, P2)

defect

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: glind, Assigned: irakli)

References

Details

Attachments

(1 file, 1 external file)

window/utils is great, but doesn't replicate `WindowTracker` use case. Under the new module, how does one track/instrument all window open and/or modify all windows. These use cases are needed in both Test Pilot and in UX feature/experiment code.
Assignee: nobody → evold
OS: Mac OS X → All
Hardware: x86 → All
Comment on attachment 710967 [details] Pointer to Github pull request: https://github.com/mozilla/addon-sdk/pull/767 I'm afraid the reason it's not being in the window/utils is because we wanted to change API. `WindowTracker` has very different API from anything else and I wanted to standardize on a single one. I've being thinking about something like: let events = require("window/events") events.on("open", onWindowOpen) events.on("close", onWindowClose) events.on("load", ...) events.on("ready", ...) ... Either that or this instead: events.open.on("*", ...) events.close.on("*", ...) .... Later has advantage that higher order functions can be trivially written to filter out chrome windows for example, or map windows to it's locations, etc... As a matter of fact I have work in progress patch for this too, but then we've started talking about integrating reducers that does basically that, and then we did not end up landing it, later I had to switch focus to something completely different. If you'd like to run this to completion, you're welcome to take over, my "cleanup/tabs" branch is place to look at: https://github.com/Gozala/addon-sdk/blob/cleanup/tabs/lib/sdk/tab/events.js
Attachment #710967 - Flags: review?(rFobic) → review-
Assignee: evold → nobody
Irakli what is the plan for replacing WindowTracker exactly? I only see bits a pieces of it in many different places. In bug 899434 you appear to have gotten upset with me for using WindowTracker and I don't see how you wish to replace it still.. If you look at the pull request 1269 for bug 899434 you should notice a race condition bug that was introduced which WindowTracker handled without any issue/hacking, and I don't see any means achieve the same result with the window/events pattern. At the moment, using window/events, it appears I have to 1. track all open windows by looping through them 2. then I have to subscribe to newly opened windows 3. then I have to make sure that windows in step 2 were not covered in step 1 (handle race condition) With WindowTracker I only had one step, register the tracker. Is there a JEP someplace for this?
Flags: needinfo?(rFobic)
Erik I did not get upset, I do not intend to sound like that. I'm just generally more picky with new code than existing one. One reason I wish to move away from WindowTracker is that it mixes too many different things, which works fine only in very specific cases. There is a big difference between windows that will become ready and once that are already ready. For one former's will be iterated immediately and later ones in the coming ticks, it may seem subtle diff but it caused some problems to me a few times, not to mention that devtools are struggling with bunch of implicit dependencies when switching form sometimes sync promises to always async ones. It's also different weather "window is closed" or weather "add-on is disabled" or "app is about to shut down". Later for example requires no actions, doing any cleanup there just slows down shut down. Now back to the pragmatism, if you just need your function to be called on every window that is ready / closed / ... it can be solved in just a few lines of code: ```js let someGoodName = fn => { const ready = windows({ includePrivates: true }). filter(isDOMContenLoaded) const DOMContentLoaded = filter(require("sdk/window/events").events, e => e.type === "DOMContentLoaded") conts futureReady = DOMContentLoaded.map(e => e.target.defaultView) ready.forEach(x => fn(x)) on("data", futureReady, fn) } ```
Flags: needinfo?(rFobic)
(In reply to Irakli Gozalishvili [:irakli] [:gozala] [@gozala] from comment #4) > > One reason I wish to move away from WindowTracker is that it mixes too many > different things, which > works fine only in very specific cases. There is a big difference between > windows that will become ready > and once that are already ready. For one former's will be iterated > immediately and later ones in the > coming ticks, it may seem subtle diff but it caused some problems to me a > few times, If that is not what is desired then it may cause confusion there, but when it is desired that is powerful, and useful, I need this use case more often than the other. I think we should have a simple solution for both use cases and we already have a solution for getting only current windows or only future windows. > not to mention > that devtools are struggling with bunch of implicit dependencies when > switching form sometimes sync promises > to always async ones. This is a different problem afaict. > It's also different weather "window is closed" or > weather "add-on is disabled" or "app is about to shut down". I'm not against deprecating WindowTracker, I just want to make sure we have something in place to cover the use cases that it covers so I can finally move on. > Now back to the pragmatism, if you just need your function to be called on > every window that is ready / closed / ... it can be solved in just a few > lines of code: > > > ```js > let someGoodName = fn => { > const ready = windows({ includePrivates: true }). > filter(isDOMContenLoaded) > const DOMContentLoaded = filter(require("sdk/window/events").events, > e => e.type === "DOMContentLoaded") > conts futureReady = DOMContentLoaded.map(e => e.target.defaultView) > > ready.forEach(x => fn(x)) > on("data", futureReady, fn) > } > ``` So as you can tell this is ~10 lines of dense hard to read code that attempts to replace `let tracker = WindowTracker({onTrack: fn});` 1 easy to read line. Also note that this snippet doesn't cover the `tracker.unload()` case.
Flags: needinfo?(rFobic)
(In reply to Erik Vold [:erikvold] [:ztatic] from comment #5) > (In reply to Irakli Gozalishvili [:irakli] [:gozala] [@gozala] from comment > #4) > > > > One reason I wish to move away from WindowTracker is that it mixes too many > > different things, which > > works fine only in very specific cases. There is a big difference between > > windows that will become ready > > and once that are already ready. For one former's will be iterated > > immediately and later ones in the > > coming ticks, it may seem subtle diff but it caused some problems to me a > > few times, > > If that is not what is desired then it may cause confusion there, but when > it is desired that is powerful, and useful, I need this use case more often > than the other. I think we should have a simple solution for both use cases > and we already have a solution for getting only current windows or only > future windows. > > > not to mention > > that devtools are struggling with bunch of implicit dependencies when > > switching form sometimes sync promises > > to always async ones. > > This is a different problem afaict. Yes but it's introduced by constructs like WindowTracker > > > It's also different weather "window is closed" or > > weather "add-on is disabled" or "app is about to shut down". > > I'm not against deprecating WindowTracker, I just want to make sure we have > something in place to cover the use cases that it covers so I can finally > move on. > > > Now back to the pragmatism, if you just need your function to be called on > > every window that is ready / closed / ... it can be solved in just a few > > lines of code: > > > > > > ```js > > let someGoodName = fn => { > > const ready = windows({ includePrivates: true }). > > filter(isDOMContenLoaded) > > const DOMContentLoaded = filter(require("sdk/window/events").events, > > e => e.type === "DOMContentLoaded") > > conts futureReady = DOMContentLoaded.map(e => e.target.defaultView) > > > > ready.forEach(x => fn(x)) > > on("data", futureReady, fn) > > } > > ``` > > So as you can tell this is ~10 lines of dense hard to read code that > attempts to replace `let tracker = WindowTracker({onTrack: fn});` 1 easy to > read line. > I believe window-tracker implementation is more than 10 lines: https://github.com/Gozala/addon-sdk/blob/master/lib/sdk/deprecated/window-utils.js#L61-L152 In addition above implementation builds on top of APIs we wanna go forward with, rather than ones we're trying to deprecate. Also maybe you misunderstood, but I meant that you can call that function some better name and put in a module so you can re-use whenever you need to do exactly that, which from what I understand is very common for new UI stuff. > Also note that this snippet doesn't cover the `tracker.unload()` case. Yes and intentionally so, as I pointed out in the pull request things you do at unload aren't necessary and they just slow-down unload. I'm sure for cases you need to handle unload you can write similar function like one above, that would invoke your fn for each window that needs to be untracked.
Flags: needinfo?(rFobic)
Hey Irakli, so we discussed how to implement our UI modules without WindowTracker and I am working on implementing what we discussed, but I have to say that I do not think that will resolve this issue. The method we discussed is complex, see https://etherpad.mozilla.org/LeKl2UN7tn I only understood this by reading that code during our 1-1 vidyo meeting.. you tried describing this with words to me many times and I never got that code snippet from your explanations, which seems like a sign to me that this will be too complex for regular add-on devs. There must be a more simple api for them imo, I have to say that while the snippet is optimal I do not think it is easy or simple to understand, and I think it is an error-prone pattern to adopt. I think for a web dev understanding WindowTracker is far easier than the pattern in https://etherpad.mozilla.org/LeKl2UN7tn and the minor optimizations from the latter are insignificant if the web dev can't understand the latter.
Flags: needinfo?(rFobic)
Mossop could you please read this thread and provide your 2c?
Flags: needinfo?(dtownsend+bugmail)
(In reply to Erik Vold [:erikvold] [:ztatic] from comment #3) > If you look at the pull request 1269 for bug 899434 you should notice a race > condition bug that was introduced which WindowTracker handled without any > issue/hacking, and I don't see any means achieve the same result with the > window/events pattern. Hey Irakli, I forget to re-mention the above when we had our 1-1 meeting, you can see the issue in your code example here https://etherpad.mozilla.org/LeKl2UN7tn (pasted below) too. Dealing with this race condition will make the code below even more complex.. do you not agree? do you see what I mean? ```js let models = {} let Model = function(options) { this.id = generateId(); this.options = options; models[id] = this; } Model.prototype.destroy = function() { remove(this); delete models[this.id]; } // controller const removeFrom = method(); removeFrom.define(Model, (window, model) => { removeModelView(window, model.id) }); const addTo = method(); addTo.define(Model, (window, model) => { const view =createView(model); addViewTo(model, view); }); const remove = model => { windows().forEach(window => removeFrom(window, model) } const add = model => { windows().forEach(window => addTo(window, model) } // wiring things up windowOpened.on("data", window => { values(models).forEach(model => add(window, model)) }) onUnload(function() { values(models).forEach(model => remove(window, model)) }) ``` A window could be in both `windows()` and `windowOpened.on("data", window => {` if it was opened before these lines executed and the 'load' event.. If you don't see what I mean we should probably schedule another meeting, I was too distracted trying to understand your code snippet to remember this last time so I apologize for that.
I have to say that I think this new pattern should be JEP'd and discussed..
I agree, we need a simple replacement for WindowTracker. Bug 940550 seems like maybe part of it but it doesn't cover everything that WindowTracker provided.
Flags: needinfo?(dtownsend+bugmail)
Priority: P2 → --
Irakli, I pointed out the race condition as a pop quiz today, it appeared to stump most people on our team, and I used code that you implemented in the sdk from the sdk/content/events module. https://etherpad.mozilla.org/3INuTUVwJq So it appears that this new pattern even stumped you, and allowed you to introduce a race condition. I've made bug 940688 about this and it provides more detail. I hope this is evidence enough that this pattern is too confusing and we should address this bug soon, finally, perhaps bug 940550 will do, but it should be JEP'd in my opinion before we start replacing WindowTacker with whatever we replace it with. In theory I think FRP will work, but I have not seen an implementation/signature in JS that I like so far. I haven't looked at everything yet though.
Assignee: nobody → rFobic
Priority: -- → P2
Erik I think we need to separate two different issues here: 1. I want us to stop using window tracker. Intend there is to wire up all events at the top level so there are no trackers per each instance. There are several reasons and I think I have named those on several occasions elsewhere so I won't list them here. What we should be doing is more or less what we discussed in the meeting and sketched out in etherpad (please treat that code as a sketch I don't have an illusion that it's working example, for working one see panel). 2. Create an alternative for `WindowTracker` for SDK users. I do agree we should do that and we need a simple replacement, although I don't think there is a huge urgency there. I don't mind users using `WindowTracker` I mind adding more dependencies on our side. For #1 we should move that discussion elsewhere and yes I think windows signal will help there. Maybe we need some sort of document similar to coding guidelines that will be design guidelines. As of #2 I have several ideas I would formulate them in JEP and we can decide which one is the best then implement.
Flags: needinfo?(rFobic)
(In reply to Erik Vold [:erikvold] [:ztatic] from comment #9) > (In reply to Erik Vold [:erikvold] [:ztatic] from comment #3) > > If you look at the pull request 1269 for bug 899434 you should notice a race > > condition bug that was introduced which WindowTracker handled without any > > issue/hacking, and I don't see any means achieve the same result with the > > window/events pattern. > > Hey Irakli, > > I forget to re-mention the above when we had our 1-1 meeting, you can see > the issue in your code example here https://etherpad.mozilla.org/LeKl2UN7tn > (pasted below) too. Dealing with this race condition will make the code > below even more complex.. do you not agree? do you see what I mean? > > ```js > let models = {} > let Model = function(options) { > this.id = generateId(); > this.options = options; > models[id] = this; > } > Model.prototype.destroy = function() { > remove(this); > delete models[this.id]; > } > // controller > const removeFrom = method(); > removeFrom.define(Model, (window, model) => { > removeModelView(window, model.id) > }); > const addTo = method(); > addTo.define(Model, (window, model) => { > const view =createView(model); > addViewTo(model, view); > }); > const remove = model => { > windows().forEach(window => removeFrom(window, model) > } > const add = model => { > windows().forEach(window => addTo(window, model) > } > // wiring things up > windowOpened.on("data", window => { > values(models).forEach(model => add(window, model)) > }) > onUnload(function() { > values(models).forEach(model => remove(window, model)) > }) > ``` > > A window could be in both `windows()` and `windowOpened.on("data", window => > {` if it was opened before these lines executed and the 'load' event.. > > If you don't see what I mean we should probably schedule another meeting, I > was too distracted trying to understand your code snippet to remember this > last time so I apologize for that. Well code we sketched out obviously requires some work, and I think I went back and forth when we were talking so that would not help either. Anyhow what I meant under `windowOpened` was actually `DOMContentLoaded` (it's just for browser windows we dispatch open on `DOMContentLoaded`) as that's a point when browser window's DOM is ready and there for it's xul can be modified. I believe during our talk I changed `windows` to something else as you did in fact pointed out this issue, and I said I meant only interactive windows. Now very basic idea is that if new menu item is added we go through existing, interactive (once's who's DOMContentLoaded occurred) browser windows and inject DOM nodes for that menu item. When new browser window becomes interactive we go through all alive menu items and inject DOM nodes into new window. Once window to becomes interactive it dispatches `DOMContentLoaded` event. So only possible way for add-on to manage to get both windows is to have it's own `DOMContentLoaded` event handler that is fired before ours, and in that handler it need's to create menu item. That way it will patch all windows and then our event listener will cause same path on the newly opened window. So yes in theory it is possible, although scenario is very unlikely. Finally I believe fixes are pretty general and several: 1. Make `addTo` not add any dom nodes if document already contains with that id. 2. Perform `add` in next tick.
BTW I don't see it in etherpad, not sure how much we talked about this during meeting but I think I pointed out in pull. I think it would be best if MenuItem would not actually call `add` or `remove` but rather dispatch observer notifications, that way you would have another channel like `menuitemAdded / menuitemRemoved` handled by `add/remove` functions. We can also make our dispatch async which will be more e10s friendly and avoid race condition you pointed out earlier.
Hey Irakli, I'm not sure if you want to work on this, if not could you please unassign yourself.
Flags: needinfo?(rFobic)
Hey Irakli, are you working on this one? if not could you please unassign yourself.
Status: NEW → RESOLVED
Closed: 11 years ago
Flags: needinfo?(rFobic)
Resolution: --- → FIXED
(In reply to Irakli Gozalishvili [:irakli] [:gozala] [@gozala] from comment #18) > This is resolved by > https://github.com/mozilla/addon-sdk/blob/master/lib/sdk/input/window.js So it looks like that module landed in https://github.com/mozilla/addon-sdk/commit/dd9779d761f7b1599878560f4141b9ddd57c0742#diff-d0596897a2849a38c60abac000d070d9 for bug 787390 but wasn't actually used in that patch anywhere, it seems unrelated to the rest of the patch, and there were no tests provided for it, so I think we should remove it at this point, since we can't be sure that it even works, nor how it is intended to work.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Attachment #8598088 - Flags: review?(dtownsend)
Attachment #8598088 - Flags: review?(dtownsend) → review+
Commits pushed to master at https://github.com/mozilla/addon-sdk https://github.com/mozilla/addon-sdk/commit/9745f11d988d4a3395d275ec08faa4de1b4e6d0e Bug 833011 Revert sdk/input/window which landed without tests and without any usages in an unrelated bug 787390 Note: to re-land please write some tests. https://github.com/mozilla/addon-sdk/commit/d61c86b1395e338870d545b9c1f7c38eae180f47 Merge pull request #1949 from erikvold/833011r Bug 833011 Revert sdk/input/window which landed without tests r=Mossop
Closing this for lots of reasons. 1. jetpack is on the way out. 2. Claim this is replicated just fine (but less elegantly) by this pattern. ``` var { modelFor } = require("sdk/model/core"); var { viewFor } = require("sdk/view/core"); var windows = require("sdk/windows").browserWindows; function affectWindow (window) { console.log("tracking",window.location); } // existing windows for (let browserWindow of windows) { console.log(`annotating (open): ${browserWindow.title}`); var chromeWindow = viewFor(browserWindow); affectWindow(chromeWindow) } // new windows // add a listener to the 'open' event windows.on('open', function(browserWindow) { console.log(`annotating (new): ${browserWindow.title}`); var chromeWindow = viewFor(browserWindow); affectWindow(chromeWindow) });
Status: REOPENED → RESOLVED
Closed: 11 years ago → 9 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: