@@ -1,241 +1,242 | |||
|
1 | 1 | import declare = require("dojo/_base/declare"); |
|
2 | 2 | import { each } from "@implab/core-amd/safe"; |
|
3 | 3 | import { Constructor } from "@implab/core-amd/interfaces"; |
|
4 | import dojo = require("dojo/_base/kernel"); | |
|
4 | 5 | |
|
5 | 6 | // declare const declare: any; |
|
6 | 7 | |
|
7 |
type DeclareConstructor<T> = d |
|
|
8 | type DeclareConstructor<T> = dojo._base.DeclareConstructor<T>; | |
|
8 | 9 | |
|
9 | 10 | export interface AbstractConstructor<T = {}> { |
|
10 | 11 | prototype: T; |
|
11 | 12 | } |
|
12 | 13 | |
|
13 | 14 | interface DjMockConstructor<T = {}> { |
|
14 | 15 | new(...args: any[]): T; |
|
15 | 16 | mock: boolean; |
|
16 | 17 | base: AbstractConstructor; |
|
17 | 18 | } |
|
18 | 19 | |
|
19 | 20 | export function djbase<T>( |
|
20 | 21 | b0: AbstractConstructor<T> |
|
21 | 22 | ): DeclareConstructor<T>; |
|
22 | 23 | |
|
23 | 24 | export function djbase<T0, T1>( |
|
24 | 25 | b0: AbstractConstructor<T0>, |
|
25 | 26 | b1: AbstractConstructor<T1> |
|
26 | 27 | ): DeclareConstructor<T0 & T1>; |
|
27 | 28 | |
|
28 | 29 | export function djbase<T0, T1, T2>( |
|
29 | 30 | b0: AbstractConstructor<T0>, |
|
30 | 31 | b1: AbstractConstructor<T1>, |
|
31 | 32 | b2: AbstractConstructor<T2> |
|
32 | 33 | ): DeclareConstructor<T0 & T1 & T2>; |
|
33 | 34 | |
|
34 | 35 | export function djbase<T0, T1, T2, T3>( |
|
35 | 36 | b0: AbstractConstructor<T0>, |
|
36 | 37 | b1: AbstractConstructor<T1>, |
|
37 | 38 | b2: AbstractConstructor<T2>, |
|
38 | 39 | b3: AbstractConstructor<T3> |
|
39 | 40 | ): DeclareConstructor<T0 & T1 & T2 & T3>; |
|
40 | 41 | |
|
41 | 42 | export function djbase<T0, T1, T2, T3, T4>( |
|
42 | 43 | b0: AbstractConstructor<T0>, |
|
43 | 44 | b1: AbstractConstructor<T1>, |
|
44 | 45 | b2: AbstractConstructor<T2>, |
|
45 | 46 | b3: AbstractConstructor<T3>, |
|
46 | 47 | b4: AbstractConstructor<T4> |
|
47 | 48 | ): DeclareConstructor<T0 & T1 & T2 & T3 & T4>; |
|
48 | 49 | |
|
49 | 50 | export function djbase<T0, T1, T2, T3, T4, T5>( |
|
50 | 51 | b0: AbstractConstructor<T0>, |
|
51 | 52 | b1: AbstractConstructor<T1>, |
|
52 | 53 | b2: AbstractConstructor<T2>, |
|
53 | 54 | b3: AbstractConstructor<T3>, |
|
54 | 55 | b4: AbstractConstructor<T4>, |
|
55 | 56 | b5: AbstractConstructor<T5> |
|
56 | 57 | ): DeclareConstructor<T0 & T1 & T2 & T3 & T4 & T5>; |
|
57 | 58 | |
|
58 | 59 | export function djbase<T0, T1, T2, T3, T4, T5, T6>( |
|
59 | 60 | b0: AbstractConstructor<T0>, |
|
60 | 61 | b1: AbstractConstructor<T1>, |
|
61 | 62 | b2: AbstractConstructor<T2>, |
|
62 | 63 | b3: AbstractConstructor<T3>, |
|
63 | 64 | b4: AbstractConstructor<T4>, |
|
64 | 65 | b5: AbstractConstructor<T5>, |
|
65 | 66 | b6: AbstractConstructor<T6> |
|
66 | 67 | ): DeclareConstructor<T0 & T1 & T2 & T3 & T4 & T5 & T6>; |
|
67 | 68 | |
|
68 | 69 | export function djbase<T0, T1, T2, T3, T4, T5, T6, T7>( |
|
69 | 70 | b0: AbstractConstructor<T0>, |
|
70 | 71 | b1: AbstractConstructor<T1>, |
|
71 | 72 | b2: AbstractConstructor<T2>, |
|
72 | 73 | b3: AbstractConstructor<T3>, |
|
73 | 74 | b4: AbstractConstructor<T4>, |
|
74 | 75 | b5: AbstractConstructor<T5>, |
|
75 | 76 | b6: AbstractConstructor<T6>, |
|
76 | 77 | b7: AbstractConstructor<T7> |
|
77 | 78 | ): DeclareConstructor<T0 & T1 & T2 & T3 & T4 & T5 & T6 & T7>; |
|
78 | 79 | |
|
79 | 80 | /** Π‘ΠΎΠ·Π΄Π°Π΅Ρ ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ-Π·Π°Π³Π»ΡΡΠΊΡ ΠΈΠ· ΡΠΏΠΈΡΠΊΠ° Π±Π°Π·ΠΎΠ²ΡΡ ΠΊΠ»Π°ΡΡΠΎΠ², ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΡΡΡ |
|
80 | 81 | * Π΄Π»Ρ ΠΎΠ±ΡΡΠ²Π»Π΅Π½ΠΈΡ ΠΊΠ»Π°ΡΡΠΎΠ² ΠΏΡΠΈ ΠΏΠΎΠΌΠΎΡΠΈ `dojo/_base/declare`. |
|
81 | 82 | * |
|
82 | 83 | * Π‘ΠΎΠ·Π΄Π°Π΅Ρ ΠΏΡΡΡΠΎΠΉ ΠΊΠΎΠ½ΡΡΡΡΡΠΎΡ, Ρ ΠΏΡΡΡΡΠΌ ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΡΠΌ ΠΏΡΠΎΡΠΎΡΠΈΠΏΠΎΠΌ, ΡΡΠΎ Π½ΡΠΆΠ½ΠΎ, |
|
83 | 84 | * ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ Π² ΡΠ½Π°ΡΠ»Π΅Π΄ΠΎΠ²Π°Π½Π½ΠΎΠΌ ΠΊΠ»Π°ΡΡΠ΅ ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΠΎ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²ΡΠ·Π²Π°ΡΡ |
|
84 | 85 | * `super(...)`, ΡΠ°ΠΊΠΈΠΌ ΠΎΠ±ΡΠ°Π·ΠΎΠΌ ΠΎΠ½ Π²ΡΠ·ΠΎΠ²Π΅Ρ ΠΏΡΡΡΡΡ ΡΡΠ½ΠΊΡΠΈΡ. |
|
85 | 86 | * |
|
86 | 87 | * Π‘ΠΎΠ·Π΄Π°Π½Π½ΡΠΉ ΠΊΠΎΠ½ΡΡΡΡΡΠΎΡ Ρ ΡΠ°Π½ΠΈΡ Π² ΡΠ΅Π±Π΅ ΡΠΏΠΈΡΠΎΠΊ Π±Π°Π·ΠΎΠ²ΡΡ ΠΊΠ»Π°ΡΡΠΎΠ², ΠΊΠΎΡΠΎΡΡΠΉ Π±ΡΠ΄Π΅Ρ |
|
87 | 88 | * ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ Π΄Π΅ΠΊΠΎΡΠ°ΡΠΎΡΠΎΠΌ `djclass`, ΠΊΠΎΡΠΎΡΡΠΉ Π²Π΅ΡΠ½Π΅Ρ ΠΊΠ»Π°ΡΡ, ΠΎΠ±ΡΡΠ²Π»Π΅Π½Π½ΡΠΉ ΠΏΡΠΈ |
|
88 | 89 | * ΠΏΠΎΠΌΠΎΡΠΈ `dojo/_base/declare`. |
|
89 | 90 | * |
|
90 | 91 | * @param bases ΡΠΏΠΈΡΠΎΠΊ Π±Π°Π·ΠΎΠ²ΡΡ ΠΊΠ»Π°ΡΡΠΎΠ², ΠΎΡ ΠΊΠΎΡΠΎΡΡΡ ΡΡΠ΅Π±ΡΠ΅ΡΡΡ ΡΠ½Π°ΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΡ |
|
91 | 92 | * Π½ΠΎΠ²ΡΠΉ ΠΊΠ»Π°ΡΡ. |
|
92 | 93 | * |
|
93 | 94 | */ |
|
94 | 95 | export function djbase(...bases: any[]): Constructor { |
|
95 | 96 | |
|
96 | 97 | const t = class { |
|
97 | 98 | static mock: boolean; |
|
98 | 99 | static base: AbstractConstructor; |
|
99 | 100 | }; |
|
100 | 101 | |
|
101 | 102 | t.mock = true; |
|
102 | 103 | t.base = declare(bases); |
|
103 | 104 | |
|
104 | 105 | return t as any; |
|
105 | 106 | } |
|
106 | 107 | |
|
107 | 108 | function isMockConstructor<T extends {}>(v: AbstractConstructor<T>): v is DjMockConstructor<T> { |
|
108 | 109 | return v && "mock" in v; |
|
109 | 110 | } |
|
110 | 111 | |
|
111 | 112 | /** Π‘ΠΎΠ·Π΄Π°Π΅Ρ ΠΊΠ»Π°ΡΡ ΠΏΡΠΈ ΠΏΠΎΠΌΠΎΡΠΈ `dojo/_base/declare`. ΠΠ»Ρ ΡΡΠΎΠ³ΠΎ ΠΈΡΡ ΠΎΠ΄Π½ΡΠΉ ΠΊΠ»Π°ΡΡ |
|
112 | 113 | * Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±ΡΡΡ ΡΠ½Π°ΡΠ»Π΅Π΄ΠΎΠ²Π°Π½ ΠΎΡ `djbase(...)`. |
|
113 | 114 | * |
|
114 | 115 | * @param target ΠΠ»Π°ΡΡ, ΠΊΠΎΡΠΎΡΡΠΉ Π½ΡΠΆΠ½ΠΎ ΠΎΠ±ΡΡΠ²ΠΈΡΡ ΠΏΡΠΈ ΠΏΠΎΠΌΠΎΡΠΈ `dojo/_base/declare` |
|
115 | 116 | */ |
|
116 | 117 | export function djclass<T extends AbstractConstructor>(target: T): T { |
|
117 | 118 | // ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ Π±Π°Π·ΠΎΠ²ΡΠΉ ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ ΠΈ Π΅Π³ΠΎ ΠΏΡΠΎΡΠΎΡΠΈΠΏ |
|
118 | 119 | let bp = target && target.prototype && Object.getPrototypeOf(target.prototype); |
|
119 | 120 | const bc = bp && bp.constructor; |
|
120 | 121 | |
|
121 | 122 | // ΠΏΡΠΎΠ²Π΅ΡΠΊΠ° ΡΠΎΠ³ΠΎ, ΡΡΠΎ ΠΊΠ»Π°ΡΡ ΡΠ½Π°ΡΠ»Π΅Π΄ΠΎΠ²Π°Π½ ΠΎΡ ΡΠΏΠ΅ΡΠΈΠ°Π»ΡΠ½ΠΎΠΉ Π·Π°Π³Π»ΡΡΠΊΠΈ |
|
122 | 123 | if (isMockConstructor(bc)) { |
|
123 | 124 | // t - Π±Π°Π·ΠΎΠ²ΡΠΉ ΠΊΠ»Π°ΡΡ, ΠΎΠ±ΡΡΠ²Π»Π΅Π½Π½ΡΠΉ ΠΏΡΠΈ ΠΏΠΎΠΌΠΎΡΠΈ dojo/_base/declare |
|
124 | 125 | const t = bc.base; |
|
125 | 126 | |
|
126 | 127 | // bc - Π±Π°Π·ΠΎΠ²ΡΠΉ ΠΊΠ»Π°ΡΡ, bc.prototype ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΡΡΡ ΠΊΠ°ΠΊ super |
|
127 | 128 | // ΠΏΡΠΈ Π²ΡΠ·ΠΎΠ²Π΅ Π±Π°Π·ΠΎΠ²ΡΡ ΠΌΠ΅ΡΠΎΠ΄ΠΎΠ². ΠΡΠΆΠ½ΠΎ ΡΠΎΠ·Π΄Π°ΡΡ bc.prototype |
|
128 | 129 | // ΡΠ°ΠΊΠΈΠΌ ΠΎΠ±ΡΠ°Π·ΠΎΠΌ, ΡΡΠΎΠ±Ρ ΠΎΠ½ Π²ΡΠ·ΡΠ²Π°Π» this.inherited(). |
|
129 | 130 | |
|
130 | 131 | // ΡΠΎΠ·Π΄Π°Π΅ΠΌ Π½ΠΎΠ²ΡΠΉ ΠΏΠΎΡΠΎΡΠΎΡΠΈΠΏ, ΠΎΠ½ Π½Π΅ Π² ΡΠ΅ΠΏΠΎΡΠΊΠ΅ ΠΏΡΠΎΡΠΎΡΠΈΠΏΠΎΠ² Ρ ΡΠ΅ΠΊΡΡΠ΅Π³ΠΎ |
|
131 | 132 | // ΠΊΠ»Π°ΡΡΠ°, Π½ΠΎ super.some_method Π±ΡΠ΄Π΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΠΈΠΌΠ΅Π½Π½ΠΎ Π΅Π³ΠΎ. |
|
132 | 133 | // Π² ΡΡΠΎΠΌ ΠΎΠ±ΡΠ΅ΠΊΡΠ΅ Π±ΡΠ΄ΡΡ ΡΠ°Π·ΠΌΠ΅ΡΠ΅Π½Ρ ΠΏΡΠΎΠΊΡΠΈ Π΄Π»Ρ ΠΏΠ΅ΡΠ΅ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½Π½ΡΡ |
|
133 | 134 | // ΠΌΠ΅ΡΠΎΠ΄ΠΎΠ². |
|
134 | 135 | bp = bc.prototype = Object.create(t.prototype); |
|
135 | 136 | bp.constructor = bc; |
|
136 | 137 | |
|
137 | 138 | // proxy - ΡΠ°Π±ΡΠΈΠΊΠ° Π΄Π»Ρ ΡΠΎΠ·Π΄Π°Π½ΠΈΡ ΠΏΡΠΎΠΊΡΠΈ-ΠΌΠ΅ΡΠΎΠ΄ΠΎΠ², ΠΊΠΎΡΠΎΡΡΠ΅ Π²Π½ΡΡΡΠΈ |
|
138 | 139 | // ΡΠ΅Π±Ρ Π²ΡΠ·ΠΎΠ²ΡΡ this.inherited Ρ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΡΠΌΠΈ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠ°ΠΌΠΈ. |
|
139 | 140 | const proxy = (m: (...args: any[]) => any) => function (this: any) { |
|
140 | 141 | const f = this.getInherited({ callee: m }); |
|
141 | 142 | return f && f.apply(this, arguments); |
|
142 | 143 | |
|
143 | 144 | // ΡΠ°ΠΊ ΡΠ΄Π΅Π»Π°ΡΡ ΠΌΠΎΠΆΠ½ΠΎ ΡΠΎΠ»ΡΠΊΠΎ dojo 1.15+ |
|
144 | 145 | // return this.inherited(m, arguments); |
|
145 | 146 | }; |
|
146 | 147 | |
|
147 | 148 | // Ρ ΡΠ΅ΠΊΡΡΠ΅Π³ΠΎ ΠΊΠ»Π°ΡΡΠ° ΠΏΡΠΎΡΠΎΡΠΈΠΏ ΡΠΎΠ΄Π΅ΡΠΆΠΈΡ ΠΌΠ΅ΡΠΎΠ΄Ρ, ΠΎΠ±ΡΡΠ²Π»Π΅Π½Π½ΡΠ΅ Π² ΡΡΠΎΠΌ |
|
148 | 149 | // ΠΊΠ»Π°ΡΡΠ΅ ΠΈ Π΅Π³ΠΎ ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ. ΠΡΠΆΠ½ΠΎ ΠΏΡΠΎΠΉΡΠΈ ΠΏΠΎ Π²ΡΠ΅ΠΌ ΠΌΠ΅ΡΠΎΠ΄Π°ΠΌ ΠΈ |
|
149 | 150 | // ΡΠΎΠ·Π΄Π°ΡΡ Π΄Π»Ρ Π½ΠΈΡ ΠΏΡΠΎΠΊΡΠΈ. |
|
150 | 151 | // ΠΡΠΈ ΡΡΠΎΠΌ ΡΠΎΠ»ΡΠΊΠΎ ΡΠ΅, ΠΌΠ΅ΡΠΎΠ΄Ρ, ΠΊΠΎΡΠΎΡΡΠ΅ Π΅ΡΡΡ Π² Π±Π°Π·ΠΎΠ²ΡΡ ΠΊΠ»Π°ΡΡΠ°Ρ |
|
151 | 152 | // ΠΌΠΎΠ³ΡΡ Π±ΡΡΡ ΠΏΠ΅ΡΠ΅ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½Ρ. |
|
152 | 153 | each(target.prototype, (m: any, p: string | number | symbol) => { |
|
153 | 154 | if (typeof m === "function" && |
|
154 | 155 | p !== "constructor" && |
|
155 | 156 | target.prototype.hasOwnProperty(p) && |
|
156 | 157 | p in t.prototype |
|
157 | 158 | ) { |
|
158 | 159 | bp[p] = proxy(m); |
|
159 | 160 | } |
|
160 | 161 | }); |
|
161 | 162 | |
|
162 | 163 | const cls = declare(t, target.prototype); |
|
163 | 164 | // TODO mixin static members |
|
164 | 165 | return cls as any; |
|
165 | 166 | } else { |
|
166 | 167 | return target as any; |
|
167 | 168 | } |
|
168 | 169 | } |
|
169 | 170 | |
|
170 | 171 | function makeSetterName(prop: string) { |
|
171 | 172 | return [ |
|
172 | 173 | "_set", |
|
173 | 174 | prop.replace(/^./, x => x.toUpperCase()), |
|
174 | 175 | "Attr" |
|
175 | 176 | ].join(""); |
|
176 | 177 | } |
|
177 | 178 | |
|
178 | 179 | function makeGetterName(prop: string) { |
|
179 | 180 | return [ |
|
180 | 181 | "_get", |
|
181 | 182 | prop.replace(/^./, x => x.toUpperCase()), |
|
182 | 183 | "Attr" |
|
183 | 184 | ].join(""); |
|
184 | 185 | } |
|
185 | 186 | |
|
186 | 187 | interface NodeBindSpec { |
|
187 | 188 | node: string; |
|
188 | 189 | type: string; |
|
189 | 190 | } |
|
190 | 191 | |
|
191 | 192 | /** |
|
192 | 193 | * ΠΠΏΠΈΡΠ°Π½ΠΈΠ΅ ΠΏΡΠΈΠ²ΡΠ·ΠΊΠΈ ΡΠ²ΠΎΠΉΡΡΠ²Π° Π²ΠΈΠ΄ΠΆΠ΅ΡΠ° ΠΊ ΡΠ²ΠΎΠΉΡΡΠ²Ρ Π²Π½ΡΡΡΠ΅Π½Π½Π΅Π³ΠΎ ΠΎΠ±ΡΠ΅ΠΊΡΠ°. |
|
193 | 194 | */ |
|
194 | 195 | interface MemberBindSpec { |
|
195 | 196 | /** |
|
196 | 197 | * ΠΠΌΡ ΡΠ²ΠΎΠΉΡΡΠ²Π° ΡΠΎ ΡΡΡΠ»ΠΊΠΎΠΉ Π½Π° ΠΎΠ±ΡΠ΅ΠΊΡ, ΠΊ ΠΊΠΎΡΠΎΡΠΎΠΌΡ . |
|
197 | 198 | */ |
|
198 | 199 | member: string; |
|
199 | 200 | /** |
|
200 | 201 | * Π‘Π²ΠΎΠΉΡΡΠ²ΠΎ ΠΎΠ±ΡΠ΅ΠΊΡΠ° ΠΊ ΠΊΠΎΡΠΎΡΠΎΠΌΡ Π½ΡΠΆΠ½ΠΎ ΠΎΡΡΡΠ΅ΡΡΠ²ΠΈΡΡ ΠΏΡΠΈΠ²ΡΠ·ΠΊΡ. |
|
201 | 202 | */ |
|
202 | 203 | property: string; |
|
203 | 204 | |
|
204 | 205 | /** |
|
205 | 206 | * ΠΡΠΈΠ²ΡΠ·ΠΊΠ° ΠΎΡΡΡΠ΅ΡΡΠ²Π»ΡΠ΅ΡΡΡ Π½Π΅ ΡΠΎΠ»ΡΠΊΠΎ Π½Π° Π·Π°ΠΏΠΈΡΡ Π½ΠΎ ΠΈ Π½Π° ΡΡΠ΅Π½ΠΈΠ΅ ΡΠ²ΠΎΠΉΡΡΠ²Π°. |
|
206 | 207 | */ |
|
207 | 208 | getter?: boolean; |
|
208 | 209 | } |
|
209 | 210 | |
|
210 | 211 | function isNodeBindSpec(v: any): v is NodeBindSpec { |
|
211 | 212 | return "node" in v; |
|
212 | 213 | } |
|
213 | 214 | |
|
214 | 215 | function isMemberBindSpec(v: any): v is MemberBindSpec { |
|
215 | 216 | return "member" in v; |
|
216 | 217 | } |
|
217 | 218 | |
|
218 | 219 | /** ΠΠ΅ΠΊΠΎΡΠΈΡΡΠ΅Ρ ΡΠ²ΠΎΠΉΡΡΠ²Π° Π²ΠΈΠ΄ΠΆΠ΅ΡΠ° Π΄Π»Ρ ΠΏΡΠΈΠ²ΡΠ·ΠΊΠΈ ΠΈΡ ΠΊ Π²Π½ΡΡΡΠ΅Π½Π½ΠΈΠΌ ΡΠ»Π΅Π½Π°ΠΌ, Π»ΠΈΠ±ΠΎ DOM |
|
219 | 220 | * ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ°ΠΌ, Π»ΠΈΠ±ΠΎ ΡΠ²ΠΎΠΉΡΡΠ²Ρ Π²Π½ΡΡΡΠ΅Π½Π½Π΅Π³ΠΎ ΠΎΠ±ΡΠ΅ΠΊΡΠ°. |
|
220 | 221 | * |
|
221 | 222 | * @param {NodeBindSpec | MemberBindSpec} params ΠΠ°ΡΠ°ΠΌΠ΅ΡΡΡ ΡΠ²ΡΠ·ΡΠ²Π°Π½ΠΈΡ. |
|
222 | 223 | */ |
|
223 | 224 | export function bind(params: NodeBindSpec | MemberBindSpec) { |
|
224 | 225 | if (isNodeBindSpec(params)) |
|
225 | 226 | return (target: any, name: string) => { |
|
226 | 227 | target[makeSetterName(name)] = params; |
|
227 | 228 | }; |
|
228 | 229 | else if (isMemberBindSpec(params)) { |
|
229 | 230 | return (target: any, name: string) => { |
|
230 | 231 | target[name] = null; |
|
231 | 232 | target[makeSetterName(name)] = function (v: any) { |
|
232 | 233 | this._set(name, v); |
|
233 | 234 | this[params.member].set(params.property, v); |
|
234 | 235 | }; |
|
235 | 236 | if (params.getter) |
|
236 | 237 | target[makeGetterName(name)] = function () { |
|
237 | 238 | return this[params.member].get(params.property); |
|
238 | 239 | }; |
|
239 | 240 | }; |
|
240 | 241 | } |
|
241 | 242 | } |
@@ -1,87 +1,88 | |||
|
1 | 1 | import { Handle } from "dojo/interfaces"; |
|
2 | 2 | import _WidgetBase = require("./_WidgetBase"); |
|
3 | 3 | import declare = require("dojo/_base/declare"); |
|
4 | import dojo = require("dojo/_base/html"); | |
|
4 | 5 | |
|
5 | 6 | declare module "./_WidgetBase" { |
|
6 | 7 | interface _WidgetBase { |
|
7 | 8 | dojoAttachEvent: string; |
|
8 | 9 | dojoAttachPoint: string; |
|
9 | 10 | } |
|
10 | 11 | } |
|
11 | 12 | |
|
12 | 13 | declare module "dojo/_base/kernel" { |
|
13 | 14 | interface Dijit { |
|
14 | 15 | _AttachMixin: _AttachMixinConstructor; |
|
15 | 16 | } |
|
16 | 17 | } |
|
17 | 18 | |
|
18 | 19 | interface _AttachMixin { |
|
19 | 20 | /** |
|
20 | 21 | * List of widget attribute names associated with data-dojo-attach-point=... in the template, ex: ["containerNode", "labelNode"] |
|
21 | 22 | */ |
|
22 | 23 | _attachPoints: string[]; |
|
23 | 24 | |
|
24 | 25 | /** |
|
25 | 26 | * List of connections associated with data-dojo-attach-event=... in the template |
|
26 | 27 | */ |
|
27 | 28 | _attachEvents: Handle[]; |
|
28 | 29 | |
|
29 | 30 | /** |
|
30 | 31 | * Object to which attach points and events will be scoped. Defaults to 'this'. |
|
31 | 32 | */ |
|
32 | 33 | attachScope: any; |
|
33 | 34 | |
|
34 | 35 | /** |
|
35 | 36 | * Search descendants of this.containerNode for data-dojo-attach-point and data-dojo-attach-event. |
|
36 | 37 | * |
|
37 | 38 | * Should generally be left false (the default value) both for performance and to avoid failures when this.containerNode holds other _AttachMixin instances with their own attach points and events. |
|
38 | 39 | */ |
|
39 | 40 | searchContainerNode: boolean; |
|
40 | 41 | |
|
41 | 42 | /** |
|
42 | 43 | * Attach to DOM nodes marked with special attributes. |
|
43 | 44 | */ |
|
44 | 45 | buildRendering(): void; |
|
45 | 46 | |
|
46 | 47 | /** |
|
47 | 48 | * hook for _WidgetsInTemplateMixin |
|
48 | 49 | */ |
|
49 | 50 | _beforeFillContent(): void; |
|
50 | 51 | |
|
51 | 52 | /** |
|
52 | 53 | * Iterate through the dom nodes and attach functions and nodes accordingly. |
|
53 | 54 | * |
|
54 | 55 | * Map widget properties and functions to the handlers specified in the dom node and it's descendants. This function iterates over all nodes and looks for these properties: |
|
55 | 56 | * - dojoAttachPoint/data-dojo-attach-point |
|
56 | 57 | * - dojoAttachEvent/data-dojo-attach-event |
|
57 | 58 | */ |
|
58 | 59 | _attachTemplateNodes(rootNode: Element | Node): void; |
|
59 | 60 | |
|
60 | 61 | /** |
|
61 | 62 | * Process data-dojo-attach-point and data-dojo-attach-event for given node or widget. |
|
62 | 63 | * |
|
63 | 64 | * Returns true if caller should process baseNode's children too. |
|
64 | 65 | */ |
|
65 | 66 | _processTemplateNode<T extends (Element | Node | _WidgetBase)>( |
|
66 | 67 | baseNode: T, |
|
67 | 68 | getAttrFunc: (baseNode: T, attr: string) => string, |
|
68 | 69 | attachFunc: (node: T, type: string, func?: Function) => Handle |
|
69 | 70 | ): boolean; |
|
70 | 71 | |
|
71 | 72 | /** |
|
72 | 73 | * Roughly corresponding to dojo/on, this is the default function for processing a data-dojo-attach-event. Meant to attach to DOMNodes, not to widgets. |
|
73 | 74 | */ |
|
74 | 75 | _attach(node: Element | Node, type: string, func?: Function): Handle; |
|
75 | 76 | |
|
76 | 77 | /** |
|
77 | 78 | * Detach and clean up the attachments made in _attachtempalteNodes. |
|
78 | 79 | */ |
|
79 | 80 | _detachTemplateNodes(): void; |
|
80 | 81 | |
|
81 | 82 | destroyRendering(preserveDom?: boolean): void; |
|
82 | 83 | } |
|
83 | 84 | |
|
84 |
interface _AttachMixinConstructor extends d |
|
|
85 | interface _AttachMixinConstructor extends dojo._base.DeclareConstructor<_AttachMixin> { } | |
|
85 | 86 | |
|
86 | 87 | declare const _AttachMixin: _AttachMixinConstructor; |
|
87 | 88 | export = _AttachMixin; |
@@ -1,138 +1,142 | |||
|
1 | import dojo = require("./kernel"); | |
|
2 | ||
|
1 | 3 | declare module "./kernel" { |
|
2 | 4 | interface Dojo { |
|
3 |
declare: d |
|
|
5 | declare: dojo._base.Declare; | |
|
4 | 6 | safeMixin: typeof declare.safeMixin; |
|
5 | 7 | } |
|
6 | } | |
|
7 | 8 | |
|
8 |
|
|
|
9 | namespace _base { | |
|
9 | 10 | interface DeclareCreatedObject { |
|
10 | 11 | declaredClass: string; |
|
11 | 12 | |
|
12 | 13 | /** |
|
13 | 14 | * Calls a super method. |
|
14 | 15 | * |
|
15 | 16 | * This method is used inside method of classes produced with |
|
16 | 17 | * declare() to call a super method (next in the chain). It is |
|
17 | 18 | * used for manually controlled chaining. Consider using the regular |
|
18 | 19 | * chaining, because it is faster. Use "this.inherited()" only in |
|
19 | 20 | * complex cases. |
|
20 | 21 | * |
|
21 | 22 | * This method cannot me called from automatically chained |
|
22 | 23 | * constructors including the case of a special (legacy) |
|
23 | 24 | * constructor chaining. It cannot be called from chained methods. |
|
24 | 25 | * |
|
25 | 26 | * If "this.inherited()" cannot find the next-in-chain method, it |
|
26 | 27 | * does nothing and returns "undefined". The last method in chain |
|
27 | 28 | * can be a default method implemented in Object, which will be |
|
28 | 29 | * called last. |
|
29 | 30 | * |
|
30 | 31 | * If "name" is specified, it is assumed that the method that |
|
31 | 32 | * received "args" is the parent method for this call. It is looked |
|
32 | 33 | * up in the chain list and if it is found the next-in-chain method |
|
33 | 34 | * is called. If it is not found, the first-in-chain method is |
|
34 | 35 | * called. |
|
35 | 36 | * |
|
36 | 37 | * If "name" is not specified, it will be derived from the calling |
|
37 | 38 | * method (using a methoid property "nom"). |
|
38 | 39 | */ |
|
39 | 40 | inherited<U>(args: IArguments, newArgs?: any[]): U; |
|
40 | 41 | inherited(args: IArguments, newArgs?: true): Function | void; |
|
41 | 42 | inherited<U>(name: string, args: IArguments, newArgs?: any[]): U; |
|
42 | 43 | inherited(name: string, args: IArguments, newArgs?: true): Function | void; |
|
43 | 44 | |
|
44 | 45 | /** |
|
45 | 46 | * Returns a super method. |
|
46 | 47 | * |
|
47 | 48 | * This method is a convenience method for "this.inherited()". |
|
48 | 49 | * It uses the same algorithm but instead of executing a super |
|
49 | 50 | * method, it returns it, or "undefined" if not found. |
|
50 | 51 | */ |
|
51 | 52 | getInherited(args: IArguments): Function | void; |
|
52 | 53 | getInherited(name: string, args: IArguments): Function | void; |
|
53 | 54 | |
|
54 | 55 | /** |
|
55 | 56 | * Checks the inheritance chain to see if it is inherited from this class. |
|
56 | 57 | * |
|
57 | 58 | * This method is used with instances of classes produced with |
|
58 | 59 | * declare() to determine of they support a certain interface or |
|
59 | 60 | * not. It models "instanceof" operator. |
|
60 | 61 | */ |
|
61 | 62 | isInstanceOf(cls: any): boolean; |
|
62 | 63 | } |
|
63 | 64 | |
|
64 | 65 | interface DeclareConstructor<T> { |
|
65 | 66 | new(...args: any[]): T & DeclareCreatedObject; |
|
66 | 67 | prototype: T; |
|
67 | 68 | |
|
68 | 69 | /** |
|
69 | 70 | * Adds all properties and methods of source to constructor's |
|
70 | 71 | * prototype, making them available to all instances created with |
|
71 | 72 | * constructor. This method is specific to constructors created with |
|
72 | 73 | * declare(). |
|
73 | 74 | * |
|
74 | 75 | * Adds source properties to the constructor's prototype. It can |
|
75 | 76 | * override existing properties. |
|
76 | 77 | * |
|
77 | 78 | * This method is similar to dojo.extend function, but it is specific |
|
78 | 79 | * to constructors produced by declare(). It is implemented |
|
79 | 80 | * using dojo.safeMixin, and it skips a constructor property, |
|
80 | 81 | * and properly decorates copied functions. |
|
81 | 82 | */ |
|
82 | 83 | extend<U>(source: U): DeclareConstructor<T & U>; |
|
83 | 84 | |
|
84 | 85 | /** |
|
85 | 86 | * Create a subclass of the declared class from a list of base classes. |
|
86 | 87 | * |
|
87 | 88 | * Create a constructor using a compact notation for inheritance and |
|
88 | 89 | * prototype extension. |
|
89 | 90 | * |
|
90 | 91 | * Mixin ancestors provide a type of multiple inheritance. |
|
91 | 92 | * Prototypes of mixin ancestors are copied to the new class: |
|
92 | 93 | * changes to mixin prototypes will not affect classes to which |
|
93 | 94 | * they have been mixed in. |
|
94 | 95 | */ |
|
95 | 96 | createSubclass<U, V, X>(mixins: [DeclareConstructor<U>, DeclareConstructor<V>], props: X): DeclareConstructor<T & U & V & X>; |
|
96 | 97 | createSubclass<U, V>(mixins: [DeclareConstructor<U>], props: V): DeclareConstructor<T & U & V>; |
|
97 | 98 | createSubclass<U, V>(mixins: DeclareConstructor<U>, props: V): DeclareConstructor<T & U & V>; |
|
98 | 99 | createSubclass<U>(mixins: [DeclareConstructor<U>]): DeclareConstructor<T & U>; |
|
99 | 100 | createSubclass<U>(mixins: DeclareConstructor<U>): DeclareConstructor<T & U>; |
|
100 | 101 | createSubclass<U>(mixins: any, props: U): DeclareConstructor<T & U>; |
|
101 | 102 | } |
|
102 | 103 | |
|
103 | 104 | interface Declare { |
|
104 | 105 | <A, B, C, D>(superClass: [DeclareConstructor<A>, DeclareConstructor<B>, DeclareConstructor<C>, DeclareConstructor<D>]): DeclareConstructor<A & B & C & D>; |
|
105 | 106 | <A, B, C>(superClass: [DeclareConstructor<A>, DeclareConstructor<B>, DeclareConstructor<C>]): DeclareConstructor<A & B & C>; |
|
106 | 107 | <A, B>(superClass: [DeclareConstructor<A>, DeclareConstructor<B>]): DeclareConstructor<A & B>; |
|
107 | 108 | <A>(superClass: DeclareConstructor<A> | [DeclareConstructor<A>]): DeclareConstructor<A>; |
|
108 | 109 | |
|
109 | 110 | <A, B, C, D, E>(superClass: [DeclareConstructor<A>, DeclareConstructor<B>, DeclareConstructor<C>, DeclareConstructor<D>], props: E): DeclareConstructor<A & B & C & D & E>; |
|
110 | 111 | <A, B, C, D>(superClass: [DeclareConstructor<A>, DeclareConstructor<B>, DeclareConstructor<C>], props: D): DeclareConstructor<A & B & C & D>; |
|
111 | 112 | <A, B, C>(superClass: [DeclareConstructor<A>, DeclareConstructor<B>], props: C): DeclareConstructor<A & B & C>; |
|
112 | 113 | <A, B>(superClass: DeclareConstructor<A> | [DeclareConstructor<A>], props: B): DeclareConstructor<A & B>; |
|
113 | 114 | |
|
114 | 115 | <A, B, C, D>(className: string, superClass: [DeclareConstructor<A>, DeclareConstructor<B>, DeclareConstructor<C>, DeclareConstructor<D>]): DeclareConstructor<A & B & C & D>; |
|
115 | 116 | <A, B, C>(className: string, superClass: [DeclareConstructor<A>, DeclareConstructor<B>, DeclareConstructor<C>]): DeclareConstructor<A & B & C>; |
|
116 | 117 | <A, B>(className: string, superClass: [DeclareConstructor<A>, DeclareConstructor<B>]): DeclareConstructor<A & B>; |
|
117 | 118 | <A>(className: string, superClass: DeclareConstructor<A> | [DeclareConstructor<A>]): DeclareConstructor<A>; |
|
118 | 119 | |
|
119 | 120 | <A, B, C, D, E>(className: string, superClass: [DeclareConstructor<A>, DeclareConstructor<B>, DeclareConstructor<C>, DeclareConstructor<D>], props: E): DeclareConstructor<A & B & C & D & E>; |
|
120 | 121 | <A, B, C, D>(className: string, superClass: [DeclareConstructor<A>, DeclareConstructor<B>, DeclareConstructor<C>], props: D): DeclareConstructor<A & B & C & D>; |
|
121 | 122 | <A, B, C>(className: string, superClass: [DeclareConstructor<A>, DeclareConstructor<B>], props: C): DeclareConstructor<A & B & C>; |
|
122 | 123 | <A, B>(className: string, superClass: DeclareConstructor<A> | [DeclareConstructor<A>], props: B): DeclareConstructor<A & B>; |
|
123 | 124 | |
|
124 | 125 | <A>(className: string, superClass: any, props: A): DeclareConstructor<A>; |
|
125 | 126 | (className: string, superClass: any): DeclareConstructor<any>; |
|
126 | 127 | <A>(superClass: any, props: A): DeclareConstructor<A>; |
|
127 | 128 | (superClass: any): DeclareConstructor<any>; |
|
128 | 129 | |
|
129 | 130 | /** |
|
130 | 131 | * Mix in properties skipping a constructor and decorating functions |
|
131 | 132 | * like it is done by declare(). |
|
132 | 133 | */ |
|
133 | 134 | safeMixin<A, B>(target: A, source: B): A & B; |
|
134 | 135 | } |
|
135 | 136 | } |
|
136 | 137 | |
|
137 | declare const declare: declare.Declare; | |
|
138 | } | |
|
139 | ||
|
140 | ||
|
141 | declare const declare: dojo._base.Declare; | |
|
138 | 142 | export = declare; |
General Comments 0
You need to be logged in to leave comments.
Login now