+ added DataStore event bus interface

This commit is contained in:
Stefan Steinhart
2015-11-17 12:47:12 +01:00
parent c560ba6f0f
commit 79e7bbf61f
2 changed files with 29 additions and 3 deletions

View File

@@ -580,3 +580,23 @@ customActionResourceInstance.DSLoadRelations('myRelation');
customActionResourceInstance.DSRefresh();
customActionResourceInstance.DSSave();
customActionResourceInstance.DSUpdate();
/**
* Events
*/
function myEvtHandler(definition:JSData.DSResourceDefinition<Resource>, item:Resource) {
}
store.on("DS.change", myEvtHandler);
store.off("DS.change", myEvtHandler);
store.emit("DS.change", customActionResource, customActionResourceInstance);
customActionResource.on("DS.change", myEvtHandler);
customActionResource.off("DS.change", myEvtHandler);
customActionResource.emit("DS.change", customActionResource, customActionResourceInstance);
customActionResourceInstance.on("DS.change", myEvtHandler);
customActionResourceInstance.off("DS.change", myEvtHandler);
customActionResourceInstance.emit("DS.change", customActionResource, customActionResourceInstance);

12
js-data/js-data.d.ts vendored
View File

@@ -105,7 +105,13 @@ declare module JSData {
resourceName:string;
}
interface DS {
interface DSEvents {
on(name:string, handler:(...args:any[])=>void):void;
off(name:string, handler:(...args:any[])=>void):void;
emit(name:string, ...args:any[]):void;
}
interface DS extends DSEvents {
new(config?:DSConfiguration):DS;
// rather undocumented
@@ -155,7 +161,7 @@ declare module JSData {
registerAdapter(adapterId:string, adapter:IDSAdapter, options?:{default: boolean}):void;
}
interface DSResourceDefinition<T> extends DSResourceDefinitionConfiguration {
interface DSResourceDefinition<T> extends DSResourceDefinitionConfiguration, DSEvents {
changeHistory(id:string | number):Array<Object>;
changes(id:string | number, options?:{ignoredChanges:Array<string|RegExp>}):Object;
clear():Array<T & DSInstanceShorthands<T>>;
@@ -191,7 +197,7 @@ declare module JSData {
}
// cannot specify T at interface level because the interface is used as generic constraint itself which ends up being recursive
export interface DSInstanceShorthands<T> {
export interface DSInstanceShorthands<T> extends DSEvents {
DSCompute():void;
DSRefresh(options?:DSAdapterOperationConfiguration):JSDataPromise<T & DSInstanceShorthands<T>>;
DSSave(options?:DSSaveConfiguration):JSDataPromise<T & DSInstanceShorthands<T>>;