本文整理汇总了TypeScript中ninejs/core/deferredUtils.when函数的典型用法代码示例。如果您正苦于以下问题:TypeScript when函数的具体用法?TypeScript when怎么用?TypeScript when使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了when函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: when
return when(self.authenticationStatus(permissions || []), function (result) {
if (result) {
return when(action.call(null, evt), function () {
return true;
});
}
else {
return when(self.login(), function () {
var d = defer();
setTimeout(function () {
when(authenticate(), function (r) {
d.resolve(r);
},
function (err) {
d.reject(err);
}
);
}, 0);
return d.promise;
}, function (err) {
console.error(err);
throw err;
});
}
}, function (err) {
开发者ID:novosit,项目名称:ninejs-auth-module,代码行数:25,代码来源:Auth.ts
示例2: function
route: '/service/login', method: 'get', handler: function (req: Request, res: Response) {
var session = req.session,
result: LoginResult;
res.set('Content-Type', 'application/json');
if (session.username) {
when(self.impl.getUser(session.username), function (data) {
if (data) {
result = {
result: 'success',
id: data.username
};
for (var p in data) {
if ((p !== 'password') && data.hasOwnProperty(p)) {
result[p] = data[p];
}
}
}
else {
result = {
result: 'failed'
};
}
res.end(JSON.stringify(result));
}, function (err) {
console.error(err);
});
}
else {
result = {
result: 'failed'
};
res.end(JSON.stringify(result));
}
}
开发者ID:novosit,项目名称:ninejs-auth-module,代码行数:34,代码来源:Auth.ts
示例3: performLogin
function performLogin() {
return when(request.post(self.config.loginUrl, {
preventCache: true,
handleAs: 'json',
withCredentials: true,
data: {user: self.userNameText.value, password: self.passwordText.value, parameters: {}}
}), function (data) {
/* globals window */
if (data.result === 'success') {
self.passwordText.value = '';
if (typeof(data.loggedInSince) === 'number') {
data.loggedInSince = new Date(data.loggedInSince);
}
setTimeout(function () {
self.emit('login', data);
}, 0);
}
else {
let skin: any = self.currentSkin;
skin.alert(data.message || 'login failed');
}
return true;
}, function (err) {
console.log(err);
});
}
开发者ID:novosit,项目名称:ninejs-auth-module,代码行数:26,代码来源:LoginScreen.ts
示例4: setTimeout
setTimeout(function () {
when(authenticate(), function (r) {
d.resolve(r);
},
function (err) {
d.reject(err);
}
);
}, 0);
开发者ID:novosit,项目名称:ninejs-auth-module,代码行数:9,代码来源:Auth.ts
示例5: authenticationStatus
authenticationStatus (requiredPermissions: (string[] | PermissionsFunction)) {
var self = this;
return when(get(this.config.loginUrl, {
preventCache: false,
handleAs: 'json',
withCredentials: true
}), function (data) {
var r = false;
if (data.result === 'success') {
self.data.mixinRecursive(data);
//data.permissions = data.permissions || [];
//self.set('userName', data.id);
//self.set('permissions', data.permissions);
if (typeof(requiredPermissions) === 'function') {
let permissionFunction = requiredPermissions as PermissionsFunction;
r = (permissionFunction(self.data['permissions']));
}
else {
let permissions: string[] = requiredPermissions as string[];
if (permissions.length) {
var cnt: number,
len = permissions.length,
current: string,
dcnt: number,
dlen = self.data['permissions'].length,
found: boolean;
r = true;
for (cnt = 0; cnt < len; cnt += 1) {
current = permissions[cnt];
found = false;
for (dcnt = 0; (dcnt < dlen) && !found; dcnt += 1) {
if (current === self.data['permissions'][dcnt]) {
found = true;
}
}
r = r && !!found;
}
}
else {
r = true;
}
}
}
else {
self.data.set('id', null);
self.data.set('permissions', []);
}
setTimeout(function () {
self.emit('login', data);
}, 0);
return r;
}, function (err) {
console.error(err);
throw err;
});
}
开发者ID:novosit,项目名称:ninejs-auth-module,代码行数:56,代码来源:Auth.ts
示例6: logout
logout () {
return when(get(this.config.logoutUrl, {
preventCache: false,
handleAs: 'json',
withCredentials: true
}), (data) => {
this.set('userName', null);
this.set('permissions', []);
this.emit('logout', data);
return true;
});
}
开发者ID:novosit,项目名称:ninejs-auth-module,代码行数:12,代码来源:Auth.ts
示例7: function
var validateUserNameBlur = function () {
var deferred = defer(),
value = this.userNameText.value,
self = this;
if (this.userNameValidation) {
when(this.userNameValidation(value), function (result) {
deferred.resolve(result);
});
}
else {
deferred.resolve(true);
}
return when(deferred.promise, function (valid) {
setClass(self.userNameIcon, '!valid', '!invalid');
if (valid) {
setClass(self.userNameIcon, 'valid');
}
else {
setClass(self.userNameIcon, 'invalid');
}
return valid;
});
};
开发者ID:novosit,项目名称:ninejs-auth-module,代码行数:23,代码来源:LoginScreen.ts
示例8: login
login (username: string, password: string, domain?: any, callback?: (data: any) => void) {
let dom: string;
if ((typeof(domain) === 'function') && !callback) {
callback = domain;
dom = null;
}
else {
dom = domain as string;
}
return when(this.impl.login(username, password, dom), function (data) {
if (callback) {
callback(data);
}
return data;
});
}
开发者ID:novosit,项目名称:ninejs-auth-module,代码行数:16,代码来源:Auth.ts
注:本文中的ninejs/core/deferredUtils.when函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论