ac.models doesn't load models when shareYUIInstance is true #585

Closed
shiweiwei97 opened this Issue Oct 2, 2012 · 5 comments

Comments

Projects
None yet
3 participants
@shiweiwei97

Mojito version: 0.4.5
Example code: https://github.com/shiweiwei97/mojito_playground/tree/master/hello_world

While accessing http://localhost:8666/my I got the following error:

[ERROR] (1349171636608) Server OutputHandler: Error 500: Cannot call method 'getData' of undefined
TypeError: Cannot call method 'getData' of undefined
    at Object.index (/Users/weiwei/mojito_playground/hello_world/mojits/myMojit/controller.server.js:32:39)
    at new ActionContext (/usr/local/lib/node_modules/mojito/lib/app/autoload/action-context.common.js:323:34)
    at Object.invoke (/usr/local/lib/node_modules/mojito/lib/app/autoload/controller-context.common.js:141:22)
    at /usr/local/lib/node_modules/mojito/lib/app/autoload/dispatch.common.js:192:28
    at [object Object]._notify (/usr/local/lib/node_modules/mojito/node_modules/yui/yui-nodejs/yui-nodejs.js:836:17)
    at /usr/local/lib/node_modules/mojito/node_modules/yui/yui-nodejs/yui-nodejs.js:817:19
    at [object Object]._notify (/usr/local/lib/node_modules/mojito/node_modules/yui/yui-nodejs/yui-nodejs.js:836:17)
    at /usr/local/lib/node_modules/mojito/node_modules/yui/yui-nodejs/yui-nodejs.js:971:27
    at [object Object]._use (/usr/local/lib/node_modules/mojito/node_modules/yui/yui-nodejs/yui-nodejs.js:1057:17)
    at [object Object].use (/usr/local/lib/node_modules/mojito/node_modules/yui/yui-nodejs/yui-nodejs.js:816:15)

I found the error occurs while the code is trying to access ac.models.myMojitModelFoo.getData().
But when shareYUIInstance is set to true, ac.models doen't have any models loaded.

Workaround: replace ac.models with Y.mojito.models.

@shiweiwei97

This comment has been minimized.

Show comment Hide comment
@shiweiwei97

shiweiwei97 Oct 3, 2012

More info: this issue occurs when model's YUI module name is not the same as its file name.
Another workaround for this issue is to rename foo.server.js to myMojitModelFoo.server.js.

Related code:
At this line, models['foo'] is set to true.
https://github.com/yahoo/mojito/blob/develop/lib/store.server.js#L687

While this line, the code is looking for models['myMojitModelFoo']. As a result the foo model was not initialized when shareYUIInstance is true.
https://github.com/yahoo/mojito/blob/develop/lib/app/autoload/controller-context.common.js#L93

More info: this issue occurs when model's YUI module name is not the same as its file name.
Another workaround for this issue is to rename foo.server.js to myMojitModelFoo.server.js.

Related code:
At this line, models['foo'] is set to true.
https://github.com/yahoo/mojito/blob/develop/lib/store.server.js#L687

While this line, the code is looking for models['myMojitModelFoo']. As a result the foo model was not initialized when shareYUIInstance is true.
https://github.com/yahoo/mojito/blob/develop/lib/app/autoload/controller-context.common.js#L93

@caridy

This comment has been minimized.

Show comment Hide comment
@caridy

caridy Oct 3, 2012

Collaborator

@shiweiwei97 in general, there were a lot of assumptions about models. The good news is that all those assumptions are going away really soon as part of 0.5.x. The bad news is that it will break your current code, so you will have to use a new API, in which case you ask for a model based on the registered name: ac.models.get('foo') (it doesn't matter if it is local or global, or if u use sharedYUIInstance or not, it will just work), and also you will have to require the models in your controller plus a new addon called mojito-models-addon.

This new API will help with performance, but also will help to produce more strict code definition of the requirements and how to access them.

Collaborator

caridy commented Oct 3, 2012

@shiweiwei97 in general, there were a lot of assumptions about models. The good news is that all those assumptions are going away really soon as part of 0.5.x. The bad news is that it will break your current code, so you will have to use a new API, in which case you ask for a model based on the registered name: ac.models.get('foo') (it doesn't matter if it is local or global, or if u use sharedYUIInstance or not, it will just work), and also you will have to require the models in your controller plus a new addon called mojito-models-addon.

This new API will help with performance, but also will help to produce more strict code definition of the requirements and how to access them.

@shiweiwei97

This comment has been minimized.

Show comment Hide comment
@shiweiwei97

shiweiwei97 Oct 7, 2012

@caridy thanks for the reply. My understanding is that this issue will be fixed in 0.5.x and code changes are required to migrate from 0.4.x and below.
But for now, I think the documentation of shareYUIInstance should be updated to let users be aware of the assumptions. Currently even the examples under https://github.com/yahoo/mojito/tree/develop/examples will break if shareYUIInstance is turned on. I myself spent hours debugging into mojito code to find out the root cause but not all users will be patient enough to do the same.

@caridy thanks for the reply. My understanding is that this issue will be fixed in 0.5.x and code changes are required to migrate from 0.4.x and below.
But for now, I think the documentation of shareYUIInstance should be updated to let users be aware of the assumptions. Currently even the examples under https://github.com/yahoo/mojito/tree/develop/examples will break if shareYUIInstance is turned on. I myself spent hours debugging into mojito code to find out the root cause but not all users will be patient enough to do the same.

@mojit0

This comment has been minimized.

Show comment Hide comment
@mojit0

mojit0 Oct 8, 2012

Contributor

Just a note, but we're unlikely to update the docs for shareYUIInstance except when we remove it entirely...which should happen in a very short time. The direction we're taking is that shareYUIInstance will be how Mojito works, and if sandboxing of separate instances is needed for a particular application the developer can do it themselves.

Contributor

mojit0 commented Oct 8, 2012

Just a note, but we're unlikely to update the docs for shareYUIInstance except when we remove it entirely...which should happen in a very short time. The direction we're taking is that shareYUIInstance will be how Mojito works, and if sandboxing of separate instances is needed for a particular application the developer can do it themselves.

@caridy

This comment has been minimized.

Show comment Hide comment
@caridy

caridy Jan 29, 2013

Collaborator

This should be fixed in 0.5.x. Closing this, feel free to reopen if you have any issue with 0.5.2+

Collaborator

caridy commented Jan 29, 2013

This should be fixed in 0.5.x. Closing this, feel free to reopen if you have any issue with 0.5.2+

@caridy caridy closed this Jan 29, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment