@@ -0,0 +1,25 | |||
|
1 | import * as _WidgetBase from "dijit/_WidgetBase"; | |
|
2 | import * as Stateful from "dojo/Stateful"; | |
|
3 | ||
|
4 | export interface IRemovable { | |
|
5 | remove(): void; | |
|
6 | } | |
|
7 | ||
|
8 | type StatefulAttrs<T> = T extends Stateful<infer A> ? A : never; | |
|
9 | ||
|
10 | interface WatchFn { | |
|
11 | <T extends Stateful, K extends keyof StatefulAttrs<T>>( | |
|
12 | target: T, | |
|
13 | prop: K, | |
|
14 | render: (model: StatefulAttrs<T>[K]) => any, | |
|
15 | own?: (obj: IRemovable) => void | |
|
16 | ); | |
|
17 | <W extends _WidgetBase, K extends keyof W>( | |
|
18 | target: W, | |
|
19 | prop: K, | |
|
20 | render: (model: W[K]) => any, | |
|
21 | own?: (obj: IRemovable) => void | |
|
22 | ); | |
|
23 | } | |
|
24 | ||
|
25 | export declare const watch: WatchFn; |
@@ -549,8 +549,65 declare namespace dijit { | |||
|
549 | 549 |
|
|
550 | 550 | } |
|
551 | 551 | |
|
552 | interface _WidgetBase { | |
|
553 | /** | |
|
554 | * Used across all instances a hash to cache attribute names and their getter | |
|
555 | * and setter names. | |
|
556 | */ | |
|
557 | _attrPairNames: { [attr: string]: string }; | |
|
558 | ||
|
559 | /** | |
|
560 | * Helper function for get() and set(). | |
|
561 | * Caches attribute name values so we don't do the string ops every time. | |
|
562 | */ | |
|
563 | _getAttrNames(name: string): string; | |
|
564 | ||
|
565 | /** | |
|
566 | * Internal helper for directly changing an attribute value. | |
|
567 | * This method id derived from Stateful and must not be used! | |
|
568 | * @deprecated use `_set(name, value)` instead. | |
|
569 | */ | |
|
570 | _changeAttrValue(name: string, value: any): this; | |
|
571 | ||
|
572 | get<K extends keyof this & string>(name: K): this[K]; | |
|
573 | ||
|
574 | /** | |
|
575 | * Helper function to set new value for specified property, and call handlers | |
|
576 | * registered with watch() if the value has changed. | |
|
577 | * @param name | |
|
578 | * @param value | |
|
579 | */ | |
|
580 | _set<K extends keyof this>(name: K, value: this[K]): void; | |
|
581 | ||
|
582 | /** | |
|
583 | * Helper function to get value for specified property stored by this._set(), | |
|
584 | * i.e. for properties with custom setters. Used mainly by custom getters. | |
|
585 | * | |
|
586 | * For example, CheckBox._getValueAttr() calls this._get("value"). | |
|
587 | * @param name | |
|
588 | */ | |
|
589 | _get<K extends keyof this>(name: K): this[K]; | |
|
590 | ||
|
591 | /** | |
|
592 | * Set a property on a Stateful instance | |
|
593 | */ | |
|
594 | set<K extends keyof this & string>(name: K, value: this[K]): this; | |
|
595 | set<K extends { [p in keyof this]: this[p] extends any[] ? p : never; }[keyof this & string]>(name: K, ...values: this[K]): this; | |
|
596 | set(values: Partial<this>): this; | |
|
597 | ||
|
598 | /** | |
|
599 | * Watches a property for changes | |
|
600 | */ | |
|
601 | watch(callback: <K extends keyof any>(prop: K, oldValue: any, newValue: any) => void): dojo.WatchHandle; | |
|
602 | watch<K extends keyof this>(name: K, callback: (prop: K, oldValue: this[K], newValue: this[K]) => void): dojo.WatchHandle; | |
|
603 | } | |
|
604 | ||
|
605 | type EventInitArgs<T extends Event> = { | |
|
606 | [p in keyof T]?: T[p] extends (...args: any) => any ? never : T[p]; | |
|
607 | }; | |
|
608 | ||
|
552 | 609 |
|
|
553 | interface _WidgetBase<Attrs = any> extends dojo.Stateful<Attrs & _WidgetBase>, Destroyable { | |
|
610 | interface _WidgetBase<Events extends { [name in keyof Events]: Event } = GlobalEventHandlersEventMap> extends Destroyable { | |
|
554 | 611 | |
|
555 | 612 | /** |
|
556 | 613 |
|
@@ -647,6 +704,8 declare namespace dijit { | |||
|
647 | 704 | */ |
|
648 | 705 |
|
|
649 | 706 | |
|
707 | _started?: boolean; | |
|
708 | ||
|
650 | 709 | /** |
|
651 | 710 |
|
|
652 | 711 | */ |
@@ -700,6 +759,7 declare namespace dijit { | |||
|
700 | 759 | /** |
|
701 | 760 |
|
|
702 | 761 |
|
|
762 | * @deprecated | |
|
703 | 763 | */ |
|
704 | 764 |
|
|
705 | 765 | |
@@ -707,11 +767,24 declare namespace dijit { | |||
|
707 | 767 |
|
|
708 | 768 |
|
|
709 | 769 | */ |
|
710 | emit(type: string, eventObj?: any, callbackArgs?: any[]): any; | |
|
770 | emit<K extends keyof Events>(eventName: K, evt: EventInitArgs<Events[K]>): void; | |
|
771 | ||
|
772 | /** | |
|
773 | * @param type | |
|
774 | * @param eventObj | |
|
775 | * @param callbackArgs | |
|
776 | */ | |
|
777 | emit<K extends string>( | |
|
778 | type: K, | |
|
779 | eventObj?: K extends keyof Events ? EventInitArgs<Events[K]> : any, | |
|
780 | callbackArgs?: any[] | |
|
781 | ): any; | |
|
711 | 782 | |
|
712 | 783 | /** |
|
713 | 784 |
|
|
714 | 785 | */ |
|
786 | on<K extends keyof Events>(eventName: K, cb: (evt: Events[K]) => void): dojo.WatchHandle; | |
|
787 | ||
|
715 | 788 |
|
|
716 | 789 | |
|
717 | 790 | /** |
@@ -732,21 +805,25 declare namespace dijit { | |||
|
732 | 805 | |
|
733 | 806 | /** |
|
734 | 807 |
|
|
808 | * @deprecated | |
|
735 | 809 | */ |
|
736 | 810 |
|
|
737 | 811 | |
|
738 | 812 | /** |
|
739 | 813 |
|
|
814 | * @deprecated | |
|
740 | 815 | */ |
|
741 | 816 |
|
|
742 | 817 | |
|
743 | 818 | /** |
|
744 | 819 |
|
|
820 | * @deprecated | |
|
745 | 821 | */ |
|
746 | 822 |
|
|
747 | 823 | |
|
748 | 824 | /** |
|
749 | 825 |
|
|
826 | * @deprecated | |
|
750 | 827 | */ |
|
751 | 828 |
|
|
752 | 829 | |
@@ -827,9 +904,9 declare namespace dijit { | |||
|
827 | 904 |
|
|
828 | 905 |
|
|
829 | 906 | |
|
830 |
|
|
|
831 |
|
|
|
832 |
|
|
|
907 | //set(name: 'month', value: number): this; | |
|
908 | //set(name: string, value: any): this; | |
|
909 | //set(values: Object): this; | |
|
833 | 910 | } |
|
834 | 911 | |
|
835 | 912 |
|
@@ -844,9 +921,9 declare namespace dijit { | |||
|
844 | 921 | */ |
|
845 | 922 |
|
|
846 | 923 | |
|
847 |
|
|
|
848 |
|
|
|
849 |
|
|
|
924 | //set(name: 'months', value: string[]): this; | |
|
925 | //set(name: string, value: any): this; | |
|
926 | //set(values: Object): this; | |
|
850 | 927 | } |
|
851 | 928 | |
|
852 | 929 |
|
@@ -907,12 +984,12 declare namespace dijit { | |||
|
907 | 984 | */ |
|
908 | 985 |
|
|
909 | 986 | |
|
910 |
|
|
|
911 |
|
|
|
912 | ||
|
913 |
|
|
|
914 |
|
|
|
915 |
|
|
|
987 | // get(name: 'value'): Date; | |
|
988 | // get(name: string): any; | |
|
989 | ||
|
990 | // set(name: 'value', value: number | Date): this; | |
|
991 | // set(name: string, value: any): this; | |
|
992 | // set(values: Object): this; | |
|
916 | 993 | } |
|
917 | 994 | |
|
918 | 995 |
|
@@ -924,9 +1001,9 declare namespace dijit { | |||
|
924 | 1001 |
|
|
925 | 1002 | |
|
926 | 1003 |
|
|
927 |
|
|
|
928 |
|
|
|
929 |
|
|
|
1004 | // set(name: 'month', value: Date): this; | |
|
1005 | // set(name: string, value: any): this; | |
|
1006 | // set(values: Object): this; | |
|
930 | 1007 | } |
|
931 | 1008 | |
|
932 | 1009 |
|
@@ -1082,12 +1159,12 declare namespace dijit { | |||
|
1082 | 1159 | */ |
|
1083 | 1160 |
|
|
1084 | 1161 | |
|
1085 |
|
|
|
1086 |
|
|
|
1087 | ||
|
1088 |
|
|
|
1089 |
|
|
|
1090 |
|
|
|
1162 | // get(name: 'value'): Date; | |
|
1163 | // get(name: string): any; | |
|
1164 | ||
|
1165 | // set(name: 'value', value: number | Date): this; | |
|
1166 | // set(name: string, value: any): this; | |
|
1167 | // set(values: Object): this; | |
|
1091 | 1168 | } |
|
1092 | 1169 | |
|
1093 | 1170 |
|
@@ -7,12 +7,12 declare module 'dijit/_Widget' { | |||
|
7 | 7 | } |
|
8 | 8 | |
|
9 | 9 | declare module 'dijit/_WidgetBase' { |
|
10 | type _WidgetBase<A = any> = dijit._WidgetBase<A>; | |
|
10 | type _WidgetBase<E extends { [k in keyof E]: Event } = {}> = dijit._WidgetBase<E & GlobalEventHandlersEventMap>; | |
|
11 | 11 | |
|
12 | 12 | // individual _WidgetBase constructor to keep type parameters |
|
13 | 13 | interface _WidgetBaseConstructor { |
|
14 |
new <A = |
|
|
15 | prototype: _WidgetBase; | |
|
14 | new <A = {}, E extends { [k in keyof E]: Event } = {}>(params?: Partial<_WidgetBase<E> & A>, srcNodeRef?: dojo.NodeOrString): _WidgetBase<E> & dojo._base.DeclareCreatedObject; | |
|
15 | prototype: _WidgetBase<any>; | |
|
16 | 16 | } |
|
17 | 17 | const _WidgetBase: _WidgetBaseConstructor; |
|
18 | 18 | export = _WidgetBase; |
@@ -1961,7 +1961,7 declare namespace dojo { | |||
|
1961 | 1961 | /** |
|
1962 | 1962 | * Watches a property for changes |
|
1963 | 1963 | */ |
|
1964 |
watch(callback: |
|
|
1964 | watch(callback:(prop: keyof any, oldValue: any, newValue: any) => void): WatchHandle; | |
|
1965 | 1965 | watch<K extends keyof T>(name: K, callback: (prop: K, oldValue: T[K], newValue: T[K]) => void): WatchHandle; |
|
1966 | 1966 | } |
|
1967 | 1967 |
@@ -724,7 +724,7 declare module 'dojo/sniff' { | |||
|
724 | 724 | } |
|
725 | 725 | |
|
726 | 726 | declare module 'dojo/Stateful' { |
|
727 |
type Stateful<T = any> = dojo.Stateful< |
|
|
727 | type Stateful<T = any> = dojo.Stateful<T>; | |
|
728 | 728 | const Stateful: dojo.StatefulConstructor; |
|
729 | 729 | export = Stateful; |
|
730 | 730 | } |
@@ -1,4 +1,5 | |||
|
1 |
import Stateful |
|
|
1 | import * as Stateful from "dojo/Stateful"; | |
|
2 | import { StatefulAttrs, watch } from "./traits"; | |
|
2 | 3 | |
|
3 | 4 | interface ScheduleAttrs { |
|
4 | 5 | title: string; |
@@ -18,4 +19,8 const model = new Schedule({duration: 10 | |||
|
18 | 19 | model.get("title"); |
|
19 | 20 | model.get("duration"); |
|
20 | 21 | |
|
21 | model.set("duration", 12); No newline at end of file | |
|
22 | model.set("duration", 12); | |
|
23 | ||
|
24 | watch(model, "duration", v => v); | |
|
25 | ||
|
26 | declare const o : StatefulAttrs<Schedule>; No newline at end of file |
@@ -1,5 +1,5 | |||
|
1 |
import Memory |
|
|
2 |
import Observable |
|
|
1 | import * as Memory from "dojo/store/Memory"; | |
|
2 | import * as Observable from "dojo/store/Observable"; | |
|
3 | 3 | |
|
4 | 4 | interface Schedule { |
|
5 | 5 | |
@@ -16,7 +16,6 const observable = new Observable(store) | |||
|
16 | 16 | |
|
17 | 17 | const mem = new Memory<Schedule>(); |
|
18 | 18 | |
|
19 | (async () => { | |
|
20 | 19 |
|
|
21 | 20 |
|
|
22 | 21 |
|
@@ -25,4 +24,3 const mem = new Memory<Schedule>(); | |||
|
25 | 24 |
|
|
26 | 25 | |
|
27 | 26 |
|
|
28 | })(); No newline at end of file |
@@ -1,17 +1,41 | |||
|
1 |
import _WidgetBase |
|
|
1 | import * as _WidgetBase from "dijit/_WidgetBase"; | |
|
2 | import { watch } from "./traits"; | |
|
2 | 3 | |
|
3 | 4 | interface ScheduleWidgetAttrs { |
|
4 | 5 | data: string[]; |
|
5 | 6 | } |
|
6 | 7 | |
|
7 | declare const w0: _WidgetBase<ScheduleWidgetAttrs>; | |
|
8 | interface ScheduleWidgetEvents { | |
|
9 | "scheduled": Event & { | |
|
10 | detail: { | |
|
11 | startDate: Date, | |
|
12 | endDate: Date | |
|
13 | } | |
|
14 | }; | |
|
15 | } | |
|
8 | 16 | |
|
9 | w0.get("data"); | |
|
10 | ||
|
11 | declare class ScheduleWidget extends _WidgetBase { | |
|
17 | declare class ScheduleWidget extends _WidgetBase<ScheduleWidgetAttrs, ScheduleWidgetEvents> { | |
|
12 | 18 | data: string[]; |
|
13 | 19 | } |
|
14 | 20 | |
|
15 | 21 | const w = new ScheduleWidget({title: "Year schedule", data: ["a", "b"] }); |
|
16 | 22 | |
|
17 | w.get("data"); No newline at end of file | |
|
23 | w.get("data"); | |
|
24 | ||
|
25 | w.watch((p, o, n) => [p,o,n]); | |
|
26 | ||
|
27 | w.watch("data", (p, o, n) => [p,o,n]); | |
|
28 | ||
|
29 | watch(w, "title", v => String(v) ); | |
|
30 | watch(w, "data", v => String(v) ); | |
|
31 | ||
|
32 | w.emit("scheduled", { detail: { startDate: new Date(), endDate: new Date()} }); | |
|
33 | ||
|
34 | w.emit("click", {} ); | |
|
35 | ||
|
36 | w.emit("click", {} ); | |
|
37 | ||
|
38 | w.emit("some-extra-event", {}); | |
|
39 | ||
|
40 | w.on("click", e => e); | |
|
41 | w.on("some-extra-event", e => e); |
@@ -5,6 +5,7 | |||
|
5 | 5 | "rootDir": "ts", |
|
6 | 6 | "rootDirs": [ |
|
7 | 7 | "ts", |
|
8 | "typings", | |
|
8 | 9 | "../main/ts" |
|
9 | 10 | ], |
|
10 | 11 | "types": [ |
@@ -12,7 +13,8 | |||
|
12 | 13 | "../main/typings/dojo/modules", |
|
13 | 14 | "../main/typings/dijit/modules" |
|
14 | 15 | ], |
|
15 |
"module": " |
|
|
16 | "module": "ESNext", | |
|
17 | "target": "ESNext" | |
|
16 | 18 | }, |
|
17 | 19 | "include": [ |
|
18 | 20 | "typings/**/*.ts", |
General Comments 0
You need to be logged in to leave comments.
Login now