forked from YahooArchive/mojito
-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller-context.common.js
224 lines (180 loc) · 8.19 KB
/
controller-context.common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
// << RIC + This is not used anymore
/*jslint anon:true, sloppy:true, nomen:true*/
/*global YUI*/
YUI.add('mojito-controller-context', function(Y, NAME) {
return;
// /**
// * @class ControllerContext
// * @constructor
// * @param {Object} opts contains instance, Y, store, appShareYUIInstance,
// * dispatch
// */
// function ControllerContext(opts) {
// this.instance = opts.instance;
// this.dispatch = opts.dispatch;
// this.store = opts.store;
// this.Y = opts.Y;
// this.shareYUIInstance = false;
// Y.mojito.util.shouldShareYUIInstance(opts.appShareYUIInstance, this.instance);
// this.init();
// }
// ControllerContext.prototype = {
// init: function() {
// var c = this.Y.mojito.controllers[this.instance['controller-module']],
// controller;
// controller = this.controller = Y.mojito.util.heir(c);
// if (Y.Lang.isFunction(controller.init)) {
// controller.init(this.instance.config);
// }
// return; // << RIC
// /*
// var error,
// // Not really an instance...more like constructor options...see
// // controller.init() call below.
// instance = this.instance,
// controller,
// shareYUIInstance = this.shareYUIInstance,
// // do a shallow merge of app-level and mojit-level configs
// // mojit config properties take precedence
// configApp = this.store.getAppConfig({}).config,
// configCombo = Y.merge(configApp, instance.config),
// // Y.mojito.controller for legacy, multi-instance.
// // Y.mojito.controllers for shared instance
// c = this.Y.mojito.controller ||
// this.Y.mojito.controllers[instance['controller-module']];
// // If sharing YUI and controller clobbers, log an error.
// if (shareYUIInstance && this.Y.mojito.controller) {
// this.Y.log(instance['controller-module'] + ' mojit' +
// ' clobbers Y.mojito.controller namespace. Please use' +
// ' `Y.namespace(\'mojito.controllers\')[NAME]` when ' +
// ' declaring controllers.', 'error', NAME);
// }
// if (!Y.Lang.isObject(c)) {
// error = new Error('Mojit controller prototype is not an' +
// ' object! (mojit id: \'' + instance.id + '\')');
// error.code = 500;
// throw error;
// }
// // we make a controller instance by using the heir() function, this
// // gives us proper function scope within the controller actions
// controller = this.controller = Y.mojito.util.heir(c);
// if (Y.Lang.isFunction(controller.init)) {
// // Use the instance data which isn't really an instance to
// // provide construction parameters for the controller init().
// controller.init(configCombo);
// }
// // mix in any (new) actions (the actions namespace here would be
// // populated by the resource store...but currently unused? Could
// // this be replaced by light inheritance to the controllers here).
// Y.Object.each(this.Y.mojito.actions, function(action, actionName) {
// this.Y.log('mixing action \'' + actionName +
// '\' into controller...', 'debug', NAME);
// controller[actionName] = function() {
// action.apply(controller, arguments);
// };
// });
// // stash the models this controller has available to be later
// // attached to the ActionContext
// this.models = {};
// Y.Object.each(this.Y.mojito.models, function(model, modelName) {
// if (!shareYUIInstance || (instance.models &&
// instance.models[modelName])) {
// // TODO: Why? There's no particular reason to inherit here.
// var modelInstance = Y.mojito.util.heir(model);
// if (Y.Lang.isFunction(modelInstance.init)) {
// // NOTE that we use the same config here that we use to
// // config the controller
// modelInstance.init(configCombo);
// }
// this.models[modelName] = modelInstance;
// }
// }, this);
// */
// },
// invoke: function(command, adapter) {
// var ac;
// try {
// ac = new this.Y.mojito.ActionContext({
// command: command,
// controller: this.controller,
// models: this.models,
// dispatch: this.dispatch,
// adapter: adapter,
// store: this.store
// });
// } catch (err) {
// console.log(err);
// this.Y.log('WARNING!! Uncaught error from dispatch on' +
// ' instance \'' + (command.instance.id || '@' + command.instance.type) +
// '\'', 'error', NAME);
// this.Y.log(err.message, 'error', NAME);
// this.Y.log(err.stack, 'error', NAME);
// }
// return; // << RIC
// /*
// var instance = this.instance,
// config = command.instance.config,
// // this is the action that will be executed
// action = command.action,
// ac,
// perfID,
// perf;
// // replace the non-expanded command instance with the proper
// // instance, that was already expanded when the controller context
// // was created
// // TODO: This may not be necessary...we did this in dispatch().
// // command.instance = instance;
// // however! we want to use the most recent config, not the cached
// // config, because that can change between action executions!
// // command.instance.config = config;
// // if there is no action, make 'index' the default
// // TODO: This may not be necessary...we did this in dispatch().
// if (!command.action) {
// // use instance config for default action or 'index'
// command.action = instance.action || 'index';
// }
// perfID = Y.mojito.perf.idFromCommand(command);
// perf = Y.mojito.perf.timeline('mojito', 'ac:ctor',
// 'create ac (which also invokes the action)', perfID);
// try {
// // Note: ac var is here to appease jslint.
// ac = new this.Y.mojito.ActionContext({
// command: command,
// controller: this.controller,
// models: this.models,
// dispatch: this.dispatch,
// adapter: adapter,
// store: this.store
// });
// // TODO: uncomment once above issue is repaired.
// // ac.invoke(command, adapter); // do it this way ;)
// } catch (err) {
// if (adapter.error) {
// adapter.error(err);
// } else {
// this.Y.log('WARNING!! Uncaught error from dispatch on' +
// ' instance \'' + (instance.id || '@' + instance.type) +
// '\'', 'error', NAME);
// this.Y.log(err.message, 'error', NAME);
// this.Y.log(err.stack, 'error', NAME);
// }
// // TODO: should we be rethrowing the error here? We log but we
// // don't ensure callers know...but then again dispatch() may
// // need this level of isolation.
// } finally {
// perf.done();
// }
// this.Y.mojito.perf.mark('mojito', 'core_dispatch_end', 'invoked action', perfID);
// */
// }
// };
// Y.namespace('mojito').ControllerContext = ControllerContext;
}, '0.1.0', {requires: [
'mojito-action-context',
'mojito-util'
]});