+ changing the JSData Promise type to interface

+ adding definitions object with usage example in tests for enabling custom type definitions of created resource definitions
This commit is contained in:
reppners
2015-03-02 21:27:20 +01:00
parent 8385575c31
commit eec429264e
2 changed files with 39 additions and 5 deletions

View File

@@ -90,13 +90,13 @@ var UserWithComputedProperty = store.defineResource<IUserWithComputedProperty>({
computed: {
// each function's argument list defines the fields
// that the computed property depends on
fullName: ['first', 'last', function (first: string, last: string) {
fullName: ['first', 'last', function (first:string, last:string) {
return first + ' ' + last;
}],
// shortand, use the array syntax above if you want
// you computed properties to work after you've
// minified your code. Shorthand style won't work when minified
initials: function (first: string, last: string) {
initials: function (first:string, last:string) {
return first.toUpperCase()[0] + '. ' + last.toUpperCase()[0] + '.';
}
}
@@ -490,4 +490,33 @@ module CustomAdapterTest {
var store = new JSData.DS();
store.registerAdapter('mca', new MyCustomAdapter(), {default: true});
// the data store will now use your custom adapter by default
}
}
/**
* showing the use of open ended interface to realize typings
* on the Datastore.definitions object where all resource definitions
* are saved.
*/
interface MyCustomDataStore {
myResource: JSData_.DSResourceDefinition<MyResourceDefinition>
}
interface MyResourceDefinition {
}
module JSData_ {
interface DS {
definitions: MyCustomDataStore;
}
}
var store = new JSData.DS();
var myResourceDefinition = store.defineResource<MyResourceDefinition>('myResource');
myResourceDefinition = store.definitions.myResource;

View File

@@ -16,7 +16,7 @@
// defining what exists in JSData and how it looks
declare module JSData_ {
class JSDataPromise<R> extends Promise<R> {
interface JSDataPromise<R> extends Promise<R> {
// enhanced with finally
finally<U>(finallyCb?:() => U):Promise<U>;
@@ -30,6 +30,10 @@ declare module JSData_ {
// rather undocumented
errors:DSErrors;
// those are objects containing the defined resources and adapters
definitions:any;
adapters:any;
defaults:DSConfiguration;
changeHistory(resourceName:string, id?:string):Array<Object>;
@@ -394,7 +398,8 @@ declare module JSData_ {
// declaring the existing global js object
declare var JSData:{
DS: JSData_.DS
DS: JSData_.DS;
DSErrors: JSData_.DSErrors;
};
//Support node require