/+junk/gjs_values

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/gjs_values

« back to all changes in this revision

Viewing changes to values.js

  • Committer: Gustav Hartvigsson
  • Date: 2014-11-23 18:35:33 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20141123183533-jey6hl523m2018fj
* got the signaling working... I think.
* Values is no longer a sub class of GObject, this to avoid the GObject
  properties handler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 */
46
46
const Values = new Lang.Class ({
47
47
  Name: 'Values',
48
 
  Extends: GObject.Object,
49
48
  
50
49
  /**
51
50
   * Name to keep track of what object we are using.
58
57
   * user defined data that may be needed when dealing with getting and
59
58
   * setting of the values:
60
59
   * <code>
61
 
    {"value1": {type: "string", user_data: {any}},
62
 
     "value2": {type: "boolean", user_data: {any}}
 
60
    {"value1": {type: "string",
 
61
                setter: function1,
 
62
                getter: function2,
 
63
                user_data: {any}},
 
64
     "value2": {type: "boolean",
 
65
                setter: function3,
 
66
                getter: function4,
 
67
                user_data: {any}}
63
68
    }
64
69
   </code>
65
70
   */
66
71
  _value_defs: {},
67
72
  
68
 
  /** @structure _values
69
 
   * Holds the data of the values in an encapsulated way, this makes it easier
70
 
   * to deal with the values.
71
 
   * <code>
72
 
    {"value1": data, "value2": data}
73
 
   </code>
74
 
   */
75
 
  _values: {},
76
 
  
77
73
  /** @structure
78
74
   * Holds the holds of the tells that listeners can listen to.
79
75
   */
88
84
  _listeners: {},
89
85
  
90
86
  _init: function (params) {
91
 
    this.parent (params);
92
87
    
93
88
    
94
89
    if (params != undefined) {
101
96
      if (params["tellers"] != undefined) {
102
97
        this._tellers = params["tellers"]
103
98
      }
 
99
      
 
100
      if (params["value_defs"] != undefined) {
 
101
        this._value_defs = params["value_defs"];
 
102
      }
104
103
    }
105
104
  },
106
105
  
120
119
        !(func instanceof Function)) {
121
120
      return false;
122
121
    }
 
122
    this._value_defs[name]["setting"] = func;
123
123
    
 
124
    return true;
124
125
  },
125
126
  
126
127
  /** @method add_value_def
132
133
   *                  and getting.
133
134
   */
134
135
  add_value_def: function (name, type, user_data) {
 
136
    if (name == undefined ||
 
137
        func == undefined ||
 
138
        this._value_defs[name] == undefined ||
 
139
        !(func instanceof Function)) {
 
140
      return false;
 
141
    }
135
142
    
136
 
  }
 
143
    return true;
 
144
  },
137
145
  
138
146
  /** @method
139
147
   * Method to get the value stored.
140
148
   */
141
149
  get_value: function (name) {
 
150
    if (name == undefined ||
 
151
        value == undefined) {
 
152
      return undefined;
 
153
    }
 
154
    if (this._value_defs[name == undefined]) {
 
155
      return undefined;
 
156
    }
142
157
    
 
158
    return this._value_defs[name]["getter"]();
143
159
  },
144
160
  
145
161
  /** @method set_value
147
163
   */
148
164
  set_value: function (name, value) {
149
165
    if (name == undefined ||
150
 
        value == undefined ||
151
 
        ) {
152
 
      return;
153
 
    }
154
 
    
155
 
  }
 
166
        value == undefined) {
 
167
      return false;
 
168
    }
 
169
    if (this._value_defs[name == undefined]) {
 
170
      return false;
 
171
    }
 
172
    this._value_defs[name]["setter"] (value, this._value_defs[name]["user_data"]);
 
173
    return true;
 
174
  },
156
175
  
157
176
  /** @method tell
158
177
   * Sends a "tell" to the listeners.
161
180
   */
162
181
  tell: function (name, user_data) {
163
182
    if (this._listeners[name] == undefined || this._tellers.indexOf (name) < 0 ) {
164
 
      return;
 
183
      return false;
165
184
    }
166
 
    for (let i = 0; i < _listeners[name].length; i++) {
 
185
    for (let i = 0; i < this._listeners[name].length; i++) {
167
186
      this._listeners[name][i](this, user_data);
168
187
    }
 
188
    return true;
169
189
  },
170
190
  
171
191
  /** @method listen
178
198
        !(func instanceof Function)) {
179
199
      return false;
180
200
    }
181
 
    
 
201
    if (this._listeners[name] == undefined) {
 
202
      this._listeners[name] = [];
 
203
    }
182
204
    this._listeners[name].push (func);
 
205
    return true;
183
206
  }
184
207
});
185
 
 
186
 
main (ARGV);