Lines Matching refs:key

6  * @fileoverview Implementation of ScreenContext class: key-value storage for
18 function checkKeyIsValid(key) {
19 var keyType = typeof key;
20 require(keyType === 'string', 'Invalid type of key: "' + keyType + '".');
38 * Returns stored value for |key| or |defaultValue| if key not found in
39 * storage. Throws Error if key not found and |defaultValue| omitted.
41 get: function(key, defaultValue) {
42 checkKeyIsValid(key);
43 if (this.hasKey(key)) {
44 return this.storage_[key];
48 throw Error('Key "' + key + '" not found.');
53 * Sets |value| for |key|. Returns true if call changes state of context,
56 set: function(key, value) {
57 checkKeyIsValid(key);
59 if (this.hasKey(key) && this.storage_[key] === value)
61 this.changes_[key] = value;
62 this.storage_[key] = value;
66 hasKey: function(key) {
67 checkKeyIsValid(key);
68 return this.storage_.hasOwnProperty(key);
81 for (var key in changes) {
82 checkKeyIsValid(key);
83 checkValueIsValid(changes[key]);
84 oldValues[key] = this.storage_[key];
85 this.storage_[key] = changes[key];
88 for (var key in changes) {
89 if (observers.hasOwnProperty(key)) {
90 var keyObservers = observers[key];
92 keyObservers[observerIndex](changes[key], oldValues[key], key);
107 addObserver: function(key, observer) {
108 if (!this.observers_.hasOwnProperty(key))
109 this.observers_[key] = [];
110 if (this.observers_[key].indexOf(observer) !== -1) {
114 this.observers_[key].push(observer);
118 for (var key in this.observers_) {
119 var observerIndex = this.observers_[key].indexOf(observer);
121 this.observers_[key].splice(observerIndex, 1);
131 for (var key in this.observers_)
132 result[key] = this.observers_[key].slice();