Reputation: 105
I successfully migrate my page from YUI2 to YUI3 and while upgrading I was using the dynamic library loading of YUI3 only including yui-min.js
and using YUI().use(...)
, but now I want to delete the local YUI2 JS's and add YUI3 locally.
I created a Global Variable var Y = YUI().use('*',function(Y){});
and changed the yui-min.js
to yui-core-min.js
and added the libs that I want to use and it works well changing Y instead YUI()
.
Y.use('datatable','datasource', function(Y){
...
fcTable = new Y.DataTable(...);
});
but I want to know if I can only call the Y.use(...)
the first time and only work with the Global Y
variable like:
...
fcTable = new Y.DataTable(...);
I think it may make the loading a litle faster, It is recomended?
Thanks 4 your time ;)
Upvotes: 0
Views: 897
Reputation: 2581
Because use()
for modules that aren't currently on the page is an asynchronous operation, you're setting up a race condition. Ignoring that, it is possible, yes.
Y.use('datatable');
will make Y.DataTable
globally available when the module resolves and is attached. The only trouble is that you can't guarantee when that will be. This is the reason for the use()
callback.
If all the module dependencies are already on the page statically (in a <script>), use()
will be synchronous, which would allow
Y.use('datatable');
var table = new Y.DataTable({ … });
But if you're including the module scripts on the page and calling use('*')
, then there's no need to explicitly call Y.use('datatable')
later, since *
attaches everything.
Upvotes: 3