Added type definitions for object-refs (#11487)

This commit is contained in:
Jan
2016-10-03 22:12:31 +02:00
committed by Mohamed Hegazy
parent 719081a255
commit c9c2a0f8fa
3 changed files with 88 additions and 0 deletions

52
object-refs/index.d.ts vendored Normal file
View File

@@ -0,0 +1,52 @@
// Type definitions for object-refs 0.1.1
// Project: https://github.com/bpmn-io/object-refs
// Definitions by: Jan Steinbruecker <https://github.com/3fd>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = Refs;
declare class Refs {
/**
* Creates a new references object defining two inversly related
* attribute descriptors a and b.
* @param {Refs.AttributeDescriptor} a property descriptor
* @param {Refs.AttributeDescriptor} b property descriptor
**/
constructor(a: Refs.AttributeDescriptor, b: Refs.AttributeDescriptor);
/**
* Binds one side of a bi-directional reference to a target object.
* @param {*} target
* @param {string|Refs.AttributeDescriptor} property
*/
bind(target: any, property: string|Refs.AttributeDescriptor): void;
ensureBound(target: any, property: string|Refs.AttributeDescriptor): void;
ensureRefsCollection(target: any, property: Refs.AttributeDescriptor): any;
set(target: any, property: string|Refs.AttributeDescriptor, value: any): void;
unset(target: any, property: string|Refs.AttributeDescriptor, value: any): void;
}
declare namespace Refs {
interface AttributeDescriptor {
name: string;
collection?: boolean;
enumerable?: boolean;
}
namespace Collection {
/** Extends a collection with Refs aware methods */
function extend(collection: any[], refs: Refs, property: string|AttributeDescriptor, target: any): any;
function isExtended(collection: any[]): boolean;
}
}

View File

@@ -0,0 +1,17 @@
import * as Refs from 'object-refs';
let refs = new Refs({ name: 'wheels', collection: true, enumerable: true }, { name: 'car' });
let car: any = { name: 'toyota' };
let wheels: any = [{ pos: 'front-left' }, { pos: 'front-right' }];
refs.bind(car, 'wheels');
car.wheels; //[]
car.wheels.add(wheels[0]);
car.wheels.add(wheels[1]);
car.wheels; // [{ pos: 'front-left' }, { pos: 'front-right' }]
wheels[0].car // { name: 'toyota' };
car.wheels.remove(wheels[0]);
wheels[0].car // undefined

19
object-refs/tsconfig.json Normal file
View File

@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": true,
"strictNullChecks": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"object-refs-tests.ts"
]
}