-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
148 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export type AttributeDescriptor = { | ||
name: string; | ||
collection?: boolean | undefined; | ||
enumerable?: boolean | undefined; | ||
} | ||
|
||
export class Refs { | ||
|
||
/** | ||
* Creates a new references object defining two inversly related | ||
* attribute descriptors a and b. | ||
* | ||
* @param a property descriptor | ||
* @param b property descriptor | ||
*/ | ||
constructor(a: AttributeDescriptor, b: AttributeDescriptor); | ||
|
||
/** | ||
* Binds one side of a bi-directional reference to a target object. | ||
* | ||
* @param target | ||
* @param property | ||
*/ | ||
bind(target: any, property: string | AttributeDescriptor): void; | ||
|
||
ensureBound(target: any, property: string | AttributeDescriptor): void; | ||
|
||
ensureRefsCollection(target: any, property: AttributeDescriptor): any; | ||
|
||
set(target: any, property: string | AttributeDescriptor, value: any): void; | ||
|
||
unset(target: any, property: string | AttributeDescriptor, value: any): void; | ||
} | ||
|
||
export namespace Collection { | ||
|
||
/** | ||
* Extends a collection with Refs aware methods | ||
*/ | ||
function extend(collection: any[], refs: Refs, property: string | AttributeDescriptor, target: any): any; | ||
|
||
/** | ||
* Checks if a given collection is extended | ||
*/ | ||
function isExtended(collection: any[]): boolean; | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
Refs, | ||
Collection | ||
} from '../../dist/index'; | ||
|
||
import { expect } from 'chai'; | ||
|
||
|
||
describe('types', function() { | ||
|
||
describe('should type Refs', function() { | ||
|
||
var refs = new Refs({ name: 'foo' }, { name: 'bar' }); | ||
|
||
|
||
it('should keep already set property', function() { | ||
|
||
// given | ||
var b = { }; | ||
var a = { foo: b }; | ||
|
||
// when | ||
refs.bind(a, 'foo'); | ||
|
||
// then | ||
expect(a.foo).to.equal(b); | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('should type Collection', function() { | ||
|
||
it('should keep already set property', function() { | ||
|
||
// when | ||
const collection = []; | ||
|
||
// then | ||
expect(Collection.isExtended(collection)).to.be.false; | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
"lib": [ | ||
"ES2018" | ||
], | ||
"strict": true, | ||
"noImplicitAny": false | ||
}, | ||
"include": [ | ||
"./dist/*.d.ts", | ||
"./test/spec/**/*.ts" | ||
] | ||
} |