Closed
Bug 869382
Opened 11 years ago
Closed 11 years ago
Static globals don't have activate(), and throw errors
Categories
(L20n :: JS Library, defect, P2)
Tracking
(Not tracked)
RESOLVED
FIXED
1.0
People
(Reporter: stas, Assigned: zbraniecki)
Details
Attachments
(1 file, 1 obsolete file)
1.65 KB,
patch
|
stas
:
review+
|
Details | Diff | Splinter Review |
@os doesn't have the activate() method and RetranslationManager::bindGet throws.
Reporter | ||
Updated•11 years ago
|
Assignee: nobody → gandalf
Priority: -- → P2
Target Milestone: --- → 1.0
Assignee | ||
Comment 1•11 years ago
|
||
Attachment #758769 -
Flags: review?(stas)
Assignee | ||
Updated•11 years ago
|
Status: NEW → ASSIGNED
Reporter | ||
Updated•11 years ago
|
Attachment #758769 -
Attachment is patch: true
Attachment #758769 -
Attachment mime type: text/x-patch → text/plain
Reporter | ||
Comment 2•11 years ago
|
||
Comment on attachment 758769 [details] [diff] [review] patch Review of attachment 758769 [details] [diff] [review]: ----------------------------------------------------------------- Wouldn't a cleaner approach be to check if activate and deactiatve is defined on the global? For instance, change this: var added = get.globals.filter(function(id) { return bound.globals.indexOf(id) === -1; }); to this (not tested): var added = get.globals.filter(function(id) { return bound.globals.indexOf(id) === -1 && this.globals[id].activate; }, this); (do this twice for all 'added' and 'removed' in bindGet) This way we wouldn't even increase/decrease the counter for static globals. Your patch work as well, so I'll leave it up to you to figure out which way you like better.
Attachment #758769 -
Flags: review?(stas) → review+
Assignee | ||
Comment 3•11 years ago
|
||
I like your idea better. How does it look for you?
Attachment #758769 -
Attachment is obsolete: true
Attachment #758886 -
Flags: review?(stas)
Reporter | ||
Comment 4•11 years ago
|
||
Comment on attachment 758886 [details] [diff] [review] patch 2 Review of attachment 758886 [details] [diff] [review]: ----------------------------------------------------------------- Cool, glad you liked it. One more potential improvement: in initGlobal, you can return right before _counter[global.id] = 0; if it's a static global. Is this correct?
Attachment #758886 -
Flags: review?(stas) → review+
Reporter | ||
Comment 5•11 years ago
|
||
Comment on attachment 758886 [details] [diff] [review] patch 2 Review of attachment 758886 [details] [diff] [review]: ----------------------------------------------------------------- ::: lib/l20n/retranslation.js @@ +76,4 @@ > // because we're just adding new entities to the bind > bound.callback = get.callback; > var added = get.globals.filter(function(id) { > + return bound.globals.indexOf(id) === -1 && this.globals[id].activate; Also, I now see that if we move these tests around, like so return this.globals[id].activate && bound.globals.indexOf(id) === -1; we might avoid one of them if activate is undefined. @@ +95,5 @@ > _counter[id]++; > this.globals[id].activate(); > }, this); > var removed = bound.globals.filter(function(id) { > + return get.globals.indexOf(id) === -1 && this.globals[id].activate; Should this check for deactivate?
Assignee | ||
Comment 6•11 years ago
|
||
https://github.com/l20n/l20n.js/commit/460a6675b245a3e1b4c18b95a2a3d759ccd977df
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Reporter | ||
Comment 7•11 years ago
|
||
(In reply to Staś Małolepszy :stas from comment #4) > One more potential improvement: in initGlobal, you can return right before > _counter[global.id] = 0; if it's a static global. Is this correct? The landing didn't address this comment. Any particular reason? (In reply to Staś Małolepszy :stas from comment #5) > @@ +95,5 @@ > > _counter[id]++; > > this.globals[id].activate(); > > }, this); > > var removed = bound.globals.filter(function(id) { > > + return get.globals.indexOf(id) === -1 && this.globals[id].activate; > > Should this check for deactivate? I back that out, sorry; I think it's asking for a bug when you define a custom global which only has deactivate.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Assignee | ||
Comment 8•11 years ago
|
||
https://github.com/l20n/l20n.js/commit/9c3a7fd5f3bca864cd6b072872003e590f061264
Status: REOPENED → RESOLVED
Closed: 11 years ago → 11 years ago
Resolution: --- → FIXED
Reporter | ||
Comment 9•11 years ago
|
||
Thanks!
Reporter | ||
Comment 10•11 years ago
|
||
There was a sneaky typo in the patch which I missed originally. I followed up with https://github.com/l20n/l20n.js/commit/18c36fa3ad39e4508b510b63b6cba24a3d8588d3b
Reporter | ||
Comment 11•11 years ago
|
||
(In reply to Staś Małolepszy :stas from comment #10) > There was a sneaky typo in the patch which I missed originally. I followed > up with > https://github.com/l20n/l20n.js/commit/ > 18c36fa3ad39e4508b510b63b6cba24a3d8588d3b The URL should be: https://github.com/l20n/l20n.js/commit/18c36fa3ad39e4508b510b63b6cba24a3d8588d3
Reporter | ||
Comment 12•11 years ago
|
||
Aaaand another followup, let's hope this time it's the last one: https://github.com/l20n/l20n.js/commit/078ea32a4f2eeff2de522023a8271b8a1a8864ce `this` wasn't set to the correct value inside of the filter functions. I mentioned this in comment 2 but then missed it in my review. Let's make it a habit to test code before we land it :)
You need to log in
before you can comment on or make changes to this bug.
Description
•