| @@ -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 | onClose(): boolean; | |
| 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 | /* dijit/_WidgetBase */ | |
| 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 | * A unique, opaque ID string that can be assigned by users or by the | |
| @@ -647,6 +704,8 declare namespace dijit { | |||||
| 647 | */ |  | 704 | */ | |
| 648 |  |  | 705 | textDir: string; | |
| 649 |  | 706 | |||
|  | 707 | _started?: boolean; | |||
|  | 708 | ||||
| 650 | /** |  | 709 | /** | |
| 651 |  |  | 710 | * Kicks off widget instantiation. See create() for details. | |
| 652 | */ |  | 711 | */ | |
| @@ -700,6 +759,7 declare namespace dijit { | |||||
| 700 | /** |  | 759 | /** | |
| 701 |  |  | 760 | * Deprecated. Override destroy() instead to implement custom widget tear-down | |
| 702 |  |  | 761 | * behavior. | |
|  | 762 | * @deprecated | |||
| 703 | */ |  | 763 | */ | |
| 704 |  |  | 764 | uninitialize(): boolean; | |
| 705 |  | 765 | |||
| @@ -707,11 +767,24 declare namespace dijit { | |||||
| 707 |  |  | 767 | * Used by widgets to signal that a synthetic event occurred, ex: | |
| 708 |  |  | 768 | * | myWidget.emit("attrmodified-selectedChildWidget", {}). | |
| 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 | * Call specified function when event occurs, ex: myWidget.on("click", function(){ ... }). | |
| 714 | */ |  | 785 | */ | |
|  | 786 | on<K extends keyof Events>(eventName: K, cb: (evt: Events[K]) => void): dojo.WatchHandle; | |||
|  | 787 | ||||
| 715 |  |  | 788 | on(type: string | dojo.ExtensionEvent, func: dojo.EventListener | Function): dojo.WatchHandle; | |
| 716 |  | 789 | |||
| 717 | /** |  | 790 | /** | |
| @@ -732,21 +805,25 declare namespace dijit { | |||||
| 732 |  | 805 | |||
| 733 | /** |  | 806 | /** | |
| 734 |  |  | 807 | * Deprecated, will be removed in 2.0, use this.own(on(...)) or this.own(aspect.after(...)) instead. | |
|  | 808 | * @deprecated | |||
| 735 | */ |  | 809 | */ | |
| 736 |  |  | 810 | connect(obj: any, event: string | dojo.ExtensionEvent, method: string | dojo.EventListener): dojo.WatchHandle; | |
| 737 |  | 811 | |||
| 738 | /** |  | 812 | /** | |
| 739 |  |  | 813 | * Deprecated, will be removed in 2.0, use handle.remove() instead. | |
|  | 814 | * @deprecated | |||
| 740 | */ |  | 815 | */ | |
| 741 |  |  | 816 | disconnect(handle: dojo.WatchHandle): void; | |
| 742 |  | 817 | |||
| 743 | /** |  | 818 | /** | |
| 744 |  |  | 819 | * Deprecated, will be removed in 2.0, use this.own(topic.subscribe()) instead. | |
|  | 820 | * @deprecated | |||
| 745 | */ |  | 821 | */ | |
| 746 |  |  | 822 | subscribe(t: string, method: dojo.EventListener): dojo.WatchHandle; | |
| 747 |  | 823 | |||
| 748 | /** |  | 824 | /** | |
| 749 |  |  | 825 | * Deprecated, will be removed in 2.0, use handle.remove() instead. | |
|  | 826 | * @deprecated | |||
| 750 | */ |  | 827 | */ | |
| 751 |  |  | 828 | unsubscribe(handle: dojo.WatchHandle): void; | |
| 752 |  | 829 | |||
| @@ -827,9 +904,9 declare namespace dijit { | |||||
| 827 |  |  | 904 | onMonthSelect(): void; | |
| 828 |  |  | 905 | postCreate(): void; | |
| 829 |  | 906 | |||
| 830 |  |  | 907 | //set(name: 'month', value: number): this; | |
| 831 |  |  | 908 | //set(name: string, value: any): this; | |
| 832 |  |  | 909 | //set(values: Object): this; | |
| 833 | } |  | 910 | } | |
| 834 |  | 911 | |||
| 835 |  |  | 912 | interface _MonthDropDownButtonConstructor extends _WidgetBaseConstructor<_MonthDropDownButton> { } | |
| @@ -844,9 +921,9 declare namespace dijit { | |||||
| 844 | */ |  | 921 | */ | |
| 845 |  |  | 922 | onChange(month: number): void; | |
| 846 |  | 923 | |||
| 847 |  |  | 924 | //set(name: 'months', value: string[]): this; | |
| 848 |  |  | 925 | //set(name: string, value: any): this; | |
| 849 |  |  | 926 | //set(values: Object): this; | |
| 850 | } |  | 927 | } | |
| 851 |  | 928 | |||
| 852 |  |  | 929 | interface _MonthDropDownConstructor extends _WidgetBaseConstructor<_MonthDropDown> { } | |
| @@ -907,12 +984,12 declare namespace dijit { | |||||
| 907 | */ |  | 984 | */ | |
| 908 |  |  | 985 | getClassForDate(dateObject: Date, locale?: string): string; | |
| 909 |  | 986 | |||
| 910 |  |  | 987 | // get(name: 'value'): Date; | |
| 911 |  |  | 988 | // get(name: string): any; | |
| 912 |  | 989 | |||
| 913 |  |  | 990 | // set(name: 'value', value: number | Date): this; | |
| 914 |  |  | 991 | // set(name: string, value: any): this; | |
| 915 |  |  | 992 | // set(values: Object): this; | |
| 916 | } |  | 993 | } | |
| 917 |  | 994 | |||
| 918 |  |  | 995 | interface CalendarConstructor extends _WidgetBaseConstructor<Calendar> { | |
| @@ -924,9 +1001,9 declare namespace dijit { | |||||
| 924 |  |  | 1001 | /* dijit/CalendarLite */ | |
| 925 |  | 1002 | |||
| 926 |  |  | 1003 | interface _MonthWidget extends _WidgetBase { | |
| 927 |  |  | 1004 | // set(name: 'month', value: Date): this; | |
| 928 |  |  | 1005 | // set(name: string, value: any): this; | |
| 929 |  |  | 1006 | // set(values: Object): this; | |
| 930 | } |  | 1007 | } | |
| 931 |  | 1008 | |||
| 932 |  |  | 1009 | interface _MonthWidgetConstructor extends _WidgetBaseConstructor<_MonthWidget> { } | |
| @@ -1082,12 +1159,12 declare namespace dijit { | |||||
| 1082 | */ |  | 1159 | */ | |
| 1083 |  |  | 1160 | getClassForDate(dateObject: Date, locale?: string): string; | |
| 1084 |  | 1161 | |||
| 1085 |  |  | 1162 | // get(name: 'value'): Date; | |
| 1086 |  |  | 1163 | // get(name: string): any; | |
| 1087 |  | 1164 | |||
| 1088 |  |  | 1165 | // set(name: 'value', value: number | Date): this; | |
| 1089 |  |  | 1166 | // set(name: string, value: any): this; | |
| 1090 |  |  | 1167 | // set(values: Object): this; | |
| 1091 | } |  | 1168 | } | |
| 1092 |  | 1169 | |||
| 1093 |  |  | 1170 | interface CalendarLiteConstructor extends _WidgetBaseConstructor<CalendarLite> { | |
| @@ -7,12 +7,12 declare module 'dijit/_Widget' { | |||||
| 7 | } |  | 7 | } | |
| 8 |  | 8 | |||
| 9 | declare module 'dijit/_WidgetBase' { |  | 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 | // individual _WidgetBase constructor to keep type parameters |  | 12 | // individual _WidgetBase constructor to keep type parameters | |
| 13 | interface _WidgetBaseConstructor { |  | 13 | interface _WidgetBaseConstructor { | |
| 14 | new <A = |  | 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; |  | 15 | prototype: _WidgetBase<any>; | |
| 16 | } |  | 16 | } | |
| 17 | const _WidgetBase: _WidgetBaseConstructor; |  | 17 | const _WidgetBase: _WidgetBaseConstructor; | |
| 18 | export = _WidgetBase; |  | 18 | export = _WidgetBase; | |
| @@ -1961,7 +1961,7 declare namespace dojo { | |||||
| 1961 | /** |  | 1961 | /** | |
| 1962 | * Watches a property for changes |  | 1962 | * Watches a property for changes | |
| 1963 | */ |  | 1963 | */ | |
| 1964 | watch(callback: |  | 1964 | watch(callback:(prop: keyof any, oldValue: any, newValue: any) => void): WatchHandle; | |
| 1965 | watch<K extends keyof T>(name: K, callback: (prop: K, oldValue: T[K], newValue: T[K]) => void): WatchHandle; |  | 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 | declare module 'dojo/Stateful' { |  | 726 | declare module 'dojo/Stateful' { | |
| 727 | type Stateful<T = any> = dojo.Stateful< |  | 727 | type Stateful<T = any> = dojo.Stateful<T>; | |
| 728 | const Stateful: dojo.StatefulConstructor; |  | 728 | const Stateful: dojo.StatefulConstructor; | |
| 729 | export = Stateful; |  | 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 | interface ScheduleAttrs { |  | 4 | interface ScheduleAttrs { | |
| 4 | title: string; |  | 5 | title: string; | |
| @@ -18,4 +19,8 const model = new Schedule({duration: 10 | |||||
| 18 | model.get("title"); |  | 19 | model.get("title"); | |
| 19 | model.get("duration"); |  | 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 |  | 1 | import * as Memory from "dojo/store/Memory"; | |
| 2 | import Observable |  | 2 | import * as Observable from "dojo/store/Observable"; | |
| 3 |  | 3 | |||
| 4 | interface Schedule { |  | 4 | interface Schedule { | |
| 5 |  | 5 | |||
| @@ -16,7 +16,6 const observable = new Observable(store) | |||||
| 16 |  | 16 | |||
| 17 | const mem = new Memory<Schedule>(); |  | 17 | const mem = new Memory<Schedule>(); | |
| 18 |  | 18 | |||
| 19 | (async () => { |  | |||
| 20 |  |  | 19 | observable.query().observe(() => { }); | |
| 21 |  |  | 20 | store.query().forEach(() => { }); | |
| 22 |  |  | 21 | const total = await store.query().total; | |
| @@ -25,4 +24,3 const mem = new Memory<Schedule>(); | |||||
| 25 |  |  | 24 | mem.query(); | |
| 26 |  | 25 | |||
| 27 |  |  | 26 | mem.add({ duration: 10, title: "Test event" }); | |
| 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 | interface ScheduleWidgetAttrs { |  | 4 | interface ScheduleWidgetAttrs { | |
| 4 | data: string[]; |  | 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"); |  | 17 | declare class ScheduleWidget extends _WidgetBase<ScheduleWidgetAttrs, ScheduleWidgetEvents> { | |
| 10 |  | ||||
| 11 | declare class ScheduleWidget extends _WidgetBase { |  | |||
| 12 | data: string[]; |  | 18 | data: string[]; | |
| 13 | } |  | 19 | } | |
| 14 |  | 20 | |||
| 15 | const w = new ScheduleWidget({title: "Year schedule", data: ["a", "b"] }); |  | 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 | "rootDir": "ts", |  | 5 | "rootDir": "ts", | |
| 6 | "rootDirs": [ |  | 6 | "rootDirs": [ | |
| 7 | "ts", |  | 7 | "ts", | |
|  | 8 | "typings", | |||
| 8 | "../main/ts" |  | 9 | "../main/ts" | |
| 9 | ], |  | 10 | ], | |
| 10 | "types": [ |  | 11 | "types": [ | |
| @@ -12,7 +13,8 | |||||
| 12 | "../main/typings/dojo/modules", |  | 13 | "../main/typings/dojo/modules", | |
| 13 | "../main/typings/dijit/modules" |  | 14 | "../main/typings/dijit/modules" | |
| 14 | ], |  | 15 | ], | |
| 15 | "module": " |  | 16 | "module": "ESNext", | |
|  | 17 | "target": "ESNext" | |||
| 16 | }, |  | 18 | }, | |
| 17 | "include": [ |  | 19 | "include": [ | |
| 18 | "typings/**/*.ts", |  | 20 | "typings/**/*.ts", | |
        
        General Comments 0
    
    
  
  
                      You need to be logged in to leave comments.
                      Login now
                    
                