Ember.application.create参数

时间:2013-03-30 06:16:29

标签: javascript ember.js requirejs

我正在探索Ember.js演示应用程序之一,除了通常的VERSION和rootElement之外,我发现很多参数都传递给Ember.Application.create()。该演示使用了我理解为AMD的require.js。

Ember.js在v1.0中是不是根据需要加载javascripts?如果它这样做,我不完全理解为什么要求require.js与它一起使用..

其次,如果require.js有一个用例,那么将控制器名称和视图名称等多个参数传递给Ember.Application.create()来引导应用程序的用法是什么。

// Define libraries
require.config({
    paths:{
        jquery:'lib/jquery-1.8.0.min',
        handlebars:'lib/handlebars',
        ember:'lib/ember_1.0pre',
        ember_data:'lib/ember-data5',
        text:'lib/require/text',
        md5:'lib/md5',
        //domready:'lib/require/domReady',
        spin:'lib/spin'
    },

    shim:{
        'ember':{
            deps:[ 'jquery', 'handlebars'],
            exports:'Ember'
        },
        'ember_data':{
            deps:[ 'ember'],
            exports:'DS'
        }
    },

      waitSeconds:15,
        urlArgs:"bust=" + (new Date()).getTime()  //cancel caching for network requests,for development.
});

// Define application
define('application', [
    'routes/app_router',
    'controllers/application_controller',
    'controllers/contacts_controller',
    'controllers/contact_controller',
    'controllers/edit_contact_controller',
    'controllers/login_controller',
    'views/application_view',
    'views/contact_in_list_view',
    'views/contacts_view',
    'views/contact_view',
    'views/edit_contact_view',
    'views/login_view',
    'models/contact',
    'jquery',
    'handlebars',
    'ember',
    'ember_data',
   // 'domready',
    'spin'

], function (Router,
                       ApplicationController,
                       ContactsController,
                        ContactController,
                        EditContactController,
                        LoginController,
                        ApplicationView,
                        Contact_In_List_View,
                        ContactsView,
                        ContactView,
                        EditContactView,
                        LoginView,
                        Contact       )
    {
        return  Ember.Application.create({
            VERSION: '1.0.0',
            rootElement:'#main',
            // Load router
            Router:Router,
            //Load Controllers
            ApplicationController:ApplicationController,
            ContactsController:ContactsController,
            ContactController:ContactController,
            EditContactController:EditContactController,
            LoginController:LoginController,
            //Load associated Views
            ApplicationView:ApplicationView,
            Contact_In_List_View:Contact_In_List_View,
            ContactsView:ContactsView,
            ContactView:ContactView,
            EditContactView:EditContactView,
            LoginView:LoginView,
            //Load Contact Model
            Contact:Contact,
            //Persistence Layer,using default RESTAdapter in ember-data.js.
            store:DS.Store.create({
                revision:5,
                adapter:DS.RESTAdapter.create({
                    bulkCommit:false,
                    serializer:DS.Serializer.create({
                        primaryKey:function (type) {
                        return type.pk;
                        }
                    }),
                    mappings:{
                        contacts:Contact
                    },
                    namespace:'api'    //you should change the first segment according to the  application's  folder path on the server.
                })
            }),
            ready:function () {
            }
        });
    }
);

Ex - application_controller.js

define('controllers/application_controller',
    ['ember' ],
    function () {
        return Ember.Controller.extend({
            loggedin:false
        });
    }
);

0 个答案:

没有答案