annotate src/implab/guard.js @ 23:1d72fddc319a

make eslint happy
author cin
date Wed, 06 Dec 2017 14:19:45 +0300
parents 9c0943c68a90
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
00779cb63b12 formatting
cin
parents: 0
diff changeset
1 define([ "./Deferred" ], function(Deferred) {
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
2 var toPromise = function(d) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
3 if (d && d.then)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
4 return d;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
5 var d2 = new Deferred();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
6 d2.resolve(d);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
7 return d2;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
8 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
9
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
10 /**
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
11 * функция для асинхронного выполнения метода
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
12 *
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
13 * @async
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
14 * @param{Object} o Объект, который будет использован в качестве
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
15 * <code>this</code>, если не указан, будет
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
16 * <code>null</code>
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
17 * @param{Function|String} m Функция или имя метода, обязательный параметр.
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
18 * Если указано имя, тогда параметр <code>o</code>
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
19 * также должен быть задан
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
20 * @param{Array} args Параметры для вызова метода, не обязательно.
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
21 * @returns{dojo/promise}
7
9c0943c68a90 minor fixes
cin
parents: 3
diff changeset
22 * @deprecated use <code>safe.async() + when()</code> instead.
0
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
23 */
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
24 return function(o, m, args) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
25 if (arguments.length == 1) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
26 m = o;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
27 o = null;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
28 } else if (arguments.length == 2 && o instanceof Function &&
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
29 m instanceof Array) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
30 args = m;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
31 m = o;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
32 o = null;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
33 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
34
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
35 try {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
36 if (!(m instanceof Function)) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
37 if (o)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
38 m = o[m];
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
39 else if (arguments.length == 1)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
40 return toPromise(m);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
41 else
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
42 throw new Error("The target object must be specified");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
43 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
44
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
45 if (!m)
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
46 throw new Error("Method not found");
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
47
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
48 return toPromise(m.apply(o, args));
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
49 } catch (err) {
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
50 var d = new Deferred();
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
51 d.reject(err);
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
52 return d;
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
53 }
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
54 };
fc2517695ee1 Initial commit, draft import of existing work
cin
parents:
diff changeset
55 });