2015-03-13 76 views
0

調用命名空間功能,我使用由彼得·蘇當在Meteor Meetup Antwerp所示的結構設計流星包唯一的方法,從不同的包

我由有根據的功能,不同的命名空間的名稱(USERAUTH,AppRoute)取得了成功我的模塊。然而,我想擁有一個特定於應用程序的命名空間UP(UserPortal)並且具有像UP.UserAuth,UP.AppRoutes這樣的命名空間。

我似乎無法調用UP.UserAuth中的函數來檢查登錄。

我上的應用程序包package.js看起來像這樣

Package.describe({ 
    name: 'up-app', 
    version: '0.0.1',  
    summary: 'User Portal Application', 

}); 

var both=['server','client']; 
var server ='server'; 
var client ='client'; 

Package.onUse(function(api) { 
    api.versionsFrom('1.0.3.2'); 
    api.use('templating',client); 
    api.use('iron:[email protected]',both); 
    api.use('tracker',both); 
    api.use('underscore',both); 
    api.use('blaze',both); 

api.use(['up-user-auth'],both); 



    api.addFiles(['lib/namespace.js','lib/routes.js'],both); 

    api.addFiles(['views/dashboard.html','views/loading.html'],client); 


    api.export('UP'); 

}); 

Package.onTest(function(api) { 
    api.use('tinytest'); 
    api.use('up-app'); 
    api.addFiles('tests/up-app-tests.js'); 
}); 

我打算用了,應用在單個封裝內宣佈我的所有應用程序的依賴關係。

我上的應用程序/ lib目錄/ routes.js文件看起來像這樣:

Router.configure({ 
    layoutTemplate: 'upDashBoard', 
    loadingTemplate: 'upLoading' 
}); 

Router.onBeforeAction(UP.UserAuth.loginRequired, { 
    except: ['login','install'] 

}); 

Router.route('/', { 
    name: 'home' 
}); 

我上用戶身份驗證包有這個在其package.js

Package.describe({ 
    name: 'up-user-auth', 
    version: '0.0.1', 
    // Brief, one-line summary of the package. 
    summary: 'User Authentication and Roles Management', 

}); 

Package.onUse(function(api) { 
    var both = ['server', 'client']; 
    var server = 'server'; 
    var client = 'client'; 


    api.versionsFrom('1.0.3.2'); 

    api.use([ 
     'tracker', 
     'service-configuration', 
     'accounts-base', 
     'underscore', 
     'templating', 
     'blaze', 
     'session', 
     'sha', 
     ] 
     ,client); 

    api.use([ 
     'tracker', 
     'service-configuration', 
     'accounts-password', 
     'accounts-base', 
     'underscore',] 
     ,server); 

    api.use(['iron:[email protected]','copleykj:mesosphere'], both); 
    api.imply(['accounts-base','accounts-password'], both); 

    api.addFiles(['lib/namespace.js','lib/loginValidation.js','lib/loginMethods.js'],both); 


    api.export('UP', both); 

}); 

Package.onTest(function(api) { 
    api.use('tinytest'); 
    api.use('up-user-auth'); 
    api.addFiles('tests/server/up-user-auth-tests.js'); 
}); 

我了/ LIB/namespace.js看起來是這樣的:

UP={}; 
UP.UserAuth={ 
    loginRequired: function() { 
     return console.log("loginControllers"); 
    } 


} 

如果我刪除了第二參考UP={};然後我得到一個錯誤說 無法設置的不確定財產「USERAUTH」但是當我加入這一切我得到的是無法讀取屬性未定義

我在做什麼錯「loginRequired」?

回答

0

你忘了聲明你的主包'up-app'的依賴關係。 每個使用名稱空間UP的包都應聲明依賴於導出名稱空間的包。

所以,只需添加

api.use('up-app', ['client', 'server']); 

在上用戶身份驗證/ package.js

KR, 彼得

+0

導致循環依賴錯誤,因爲上的應用程序使用向上用戶身份驗證是爲了訪問UP.UserAuth。 – Churchill 2015-04-01 10:11:16