本文整理匯總了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) {
示例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));
}
}
示例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);
});
}
示例4: setTimeout
setTimeout(function () {
when(authenticate(), function (r) {
d.resolve(r);
},
function (err) {
d.reject(err);
}
);
}, 0);
示例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;
});
}
示例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;
});
}
示例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;
});
};
示例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;
});
}