Chromium Code Reviews| Index: chrome/common/extensions/docs/examples/extensions/buildbot/active_issues.js |
| diff --git a/chrome/common/extensions/docs/examples/extensions/buildbot/active_issues.js b/chrome/common/extensions/docs/examples/extensions/buildbot/active_issues.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c576f19a2428e43f8c85887df8178d6f32731284 |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/examples/extensions/buildbot/active_issues.js |
| @@ -0,0 +1,64 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +(function(){ |
| + |
| +window.ActiveIssues = function(stateObject) { |
|
not at google - send to devlin
2013/07/04 00:37:11
ditto, buildbot.ActiveIssues
Mike Wittman
2013/07/16 17:53:19
Done.
|
| + this.issues_ = stateObject; |
| + |
| + if (window === chrome.extension.getBackgroundPage()) { |
| + var thisObj = this; |
|
not at google - send to devlin
2013/07/04 00:37:11
idiomatically this is 'self'?
also if there was o
Mike Wittman
2013/07/16 17:53:19
I've moved to a singleton implementation with call
|
| + chrome.extension.onConnect.addListener(function(port) { |
| + if (port.name == thisObj.portName_) { |
| + thisObj.port_ = port; |
| + port.onDisconnect.addListener(function() { thisObj.port_ = null; }); |
| + } |
| + }); |
| + } |
| +}; |
| + |
| +window.ActiveIssues.prototype = { |
| + forEach: function(callback) { |
| + for (var key in this.issues_) |
| + callback(this.issues_[key]); |
|
not at google - send to devlin
2013/07/04 00:37:11
simpler as this.issues_.forEach(callback)?
Mike Wittman
2013/07/16 17:53:19
this.issues_ is an Object rather than an Array. I
|
| + }, |
| + |
| + getIssue: function(number) { |
| + return this.issues_[number]; |
| + }, |
| + |
| + updateIssue: function(issue) { |
| + var eventType = this.issues_.hasOwnProperty(issue.issue) ? |
| + "issueUpdated" : "issueAdded"; |
| + this.issues_[issue.issue] = issue; |
| + if (this.port_) |
| + this.port_.postMessage({event: eventType, issue: issue.issue}); |
| + }, |
| + |
| + removeIssue: function(issue) { |
| + delete this.issues_[issue.issue]; |
| + if (this.port_) |
| + this.port_.postMessage({event: "issueRemoved", issue: issue.issue}); |
| + }, |
| + |
| + connectEventsPort: function() { |
| + return chrome.runtime.connect({name: this.portName_}); |
| + }, |
| + |
| + portName_: "ActiveIssues" |
| +}; |
| + |
| +window.getActiveIssues = function() { |
| + var stateObjectKey = "activeIssuesState"; |
| + var background = chrome.extension.getBackgroundPage(); |
| + if (!background.hasOwnProperty(stateObjectKey)) |
| + background[stateObjectKey] = {}; |
| + |
| + var key = "activeIssues"; |
| + if (!window.hasOwnProperty(key)) |
| + window[key] = new ActiveIssues(background[stateObjectKey]); |
| + return window[key]; |
|
not at google - send to devlin
2013/07/04 00:37:11
(responding to earlier comment)
Cool, yeah I get/
Mike Wittman
2013/07/16 17:53:19
I've converted over to a singleton. I had misattri
|
| +}; |
| + |
| +})(); |