diff --git a/stampit/stampit-1.2.0.d.ts b/stampit/stampit-1.2.0.d.ts deleted file mode 100644 index 8d46e7477..000000000 --- a/stampit/stampit-1.2.0.d.ts +++ /dev/null @@ -1,155 +0,0 @@ -// Type definitions for stampit -// Project: https://github.com/ericelliott/stampit -// Definitions by: Vasyl Boroviak -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -declare var stampit: stampit.Stampit; - -declare module stampit { - interface Stampit { - /** - * Return a factory (akaStamp) function that will produce new objects using the - * prototypes that are passed in or composed. - * @param methods A map of method names and bodies for delegation. - * @param state A map of property names and values to clone for each new object. - * @param enclose A closure (function) used to create private data and privileged methods. - * */ - (methods?:{}, state?:{}, enclose?:{(...encloseArgs:any[]): void}[]):stampit.Stamp; - - /** - * Take two or more Stamps and combine them to produce a new Stamp. - * Combining overrides properties with last-in priority. - * @param stamps Stamps produced by stampit. - * @return A new Stamp made of all the given. - */ - compose(...stamps:Stamp[]): Stamp; - - /** - * Take a destination object followed by one or more source objects, - * and copy the source object properties to the destination object, - * with last in priority overrides. - * @param destination An object to copy properties to. - * @param source Objects to copy properties from. - * @return The destination object. - */ - mixIn(destination:any, ...source:any[]): any; - - /** - * Alias for mixIn. - * Take a destination object followed by one or more source objects, - * and copy the source object properties to the destination object, - * with last in priority overrides. - * @param destination An object to copy properties to. - * @param source Objects to copy properties from. - * @return The destination object. - */ - extend(destination:any, ...source:any[]): any; - - /** - * Check if an object is a Stamp. - * @param obj An object to check. - * @return true if the object is a Stamp; otherwise - false. - */ - isStamp(obj:any): boolean; - - /** - * Take an old-fashioned JS constructor and return a Stamp - * that you can freely compose with other Stamps. - * @param Constructor Old-fashioned constructor function. - * @return A new Stamp based on the given constructor. - */ - convertConstructor(Constructor:any): Stamp; - } - - /** - * A factory function that will produce new objects using the - * prototypes that are passed in or composed. - */ - export interface Stamp { - /** - * Just like calling stamp() invokes the stamp and returns a new object instance. - * @param state Properties you wish to set on the new objects. - * @param encloseArgs The remaining arguments are passed to all .enclose() functions. - * WARNING Avoid using two different .enclose() functions that expect different arguments. - * .enclose() functions that take arguments should not be considered safe to compose - * with other .enclose() functions that also take arguments. Taking arguments with - * an .enclose() function is an anti-pattern that should be avoided, when possible. - * @return A new object composed of the Stamps and prototypes provided. - */ - (state?:{}, ...encloseArgs:any[]): any; - - /** - * Just like calling stamp(), stamp.create() invokes the stamp and returns a new instance. - * @param state Properties you wish to set on the new objects. - * @param encloseArgs The remaining arguments are passed to all .enclose() functions. - * WARNING Avoid using two different .enclose() functions that expect different arguments. - * .enclose() functions that take arguments should not be considered safe to compose - * with other .enclose() functions that also take arguments. Taking arguments with - * an .enclose() function is an anti-pattern that should be avoided, when possible. - * @return A new object composed of the Stamps and prototypes provided. - */ - create(state?:{}, ...encloseArgs:any[]): any; - - /** - * An object map containing the fixed prototypes. - */ - fixed: Fixed; - - /** - * Add methods to the methods prototype. Chainable. - * @param methods Object(s) containing map of method names and bodies for delegation. - * @return Self. - */ - methods(...methods:{}[]): Stamp; - - /** - * Take n objects and add them to the state prototype. Changes `this` object. Chainable. - * @param states Object(s) containing map of property names and values to clone for each new object. - * @return Self. - */ - state(...states:{}[]): Stamp; - - /** - * Take n functions, an array of functions, or n objects and add the functions to the enclose prototype. - * Functions passed into .enclose() are called any time an object is instantiated. - * That happens when the stamp function is invoked, or when the .create() method is called. - * Changes `this` object. Chainable. - * @param functions Closures (functions) used to create private data and privileged methods. - * @return Self. - */ - enclose(...functions:{(...encloseArgs:any[]): void}[]): Stamp; - - /** - * Take n functions, an array of functions, or n objects and add the functions to the enclose prototype. - * Functions passed into .enclose() are called any time an object is instantiated. - * That happens when the stamp function is invoked, or when the .create() method is called. - * Changes `this` object. Chainable. - * @param methods Function properties of these objects will be treated as closure functions. - * @return Self. - */ - enclose(...methods:{}[]): Stamp; - - /** - * Take one or more Stamps and - * combine them with `this` to produce and return a new Stamp. - * Combining overrides properties with last-in priority. - * NOT chainable. - * @param stamps Stampit factories, aka Stamps. - * @return A new Stamp composed from arguments and `this`. - */ - compose(...stamps:Stamp[]): Stamp; - } - - /** - * An object map containing the fixed prototypes. - */ - interface Fixed { - methods: {}; - state: {}; - enclose: {(...encloseArgs:any[]): void}[]; - } -} - -declare module "stampit" { - export = stampit; -} \ No newline at end of file diff --git a/stampit/stampit-tests-1.2.0.ts b/stampit/stampit-tests-1.2.0.ts deleted file mode 100644 index ce404651a..000000000 --- a/stampit/stampit-tests-1.2.0.ts +++ /dev/null @@ -1,168 +0,0 @@ -/// - -var a = stampit().enclose(() => { - var a = 'a'; - this.getA = () => { - return a; - }; -}); -a(); // Object -- so far so good. -a().getA(); // "a" - - -var b = stampit().enclose(function () { - var a = 'b'; - this.getB = function () { - return a; - }; -}); - - -var c = stampit.compose(a, b); -var foo = c(); // we won't throw this one away... -foo.getA(); // "a" -foo.getB(); // "b" - - -// Some more privileged methods, with some private data. -// Use stampit.mixIn() to make this feel declarative: -var availability = stampit().enclose(function () { - var isOpen = false; // private - - return stampit.mixIn(this, { - open: function open() { - isOpen = true; - return this; - }, - close: function close() { - isOpen = false; - return this; - }, - isOpen: function isOpenMethod() { - return isOpen; - } - }); -}); -// Hre's a mixin with public methods, and some state: -var membership = stampit({ - members: {}, - add: function (member: any) { - this.members[member.name] = member; - return this; - }, - getMember: function (name: any) { - return this.members[name]; - } - }, - { - members: {} - }); -// Let's set some defaults: -var defaults = stampit().state({ - name: 'The Saloon', - specials: 'Whisky, Gin, Tequila' -}); - -// Classical inheritance has nothing on this. No parent/child coupling. No deep inheritance hierarchies. -// Just good, clean code reusability. -var bar = stampit.compose(defaults, availability, membership); -// Note that you can override state on instantiation: -var myBar = bar({name: 'Moe\'s'}); -// Silly, but proves that everything is as it should be. -myBar.add({name: 'Homer' }).open().getMember('Homer'); - - - -var myStamp = stampit().methods({ - foo: function () { - return 'foo'; - }, - methodOverride: function () { - return false; - } -}).methods({ - bar: function () { - return 'bar' - }, - methodOverride: function () { - return true; - } -}); - -myStamp.state({ - foo: {bar: 'bar'}, - stateOverride: false -}).state({ - bar: 'bar', - stateOverride: true -}); - -myStamp.enclose(function () { - var secret = 'foo'; - - this.getSecret = function () { - return secret; - }; -}).enclose(function () { - this.a = true; -}).enclose({ - bar: function bar() { - this.b = true; - } -}, { - baz: function baz() { - this.c = true; - } -}); - -var obj = myStamp.create(); -obj.getSecret && obj.a && obj.b && obj.c; // true - -var newStamp = stampit(null, { defaultNum: 1 }).compose(myStamp); - - - -var obj1 = stampit().methods({ - a: function () { return 'a'; } -}, { - b: function () { return 'b'; } -}).create(); - -var obj2 = stampit().state({ - a: 'a' -}, { - b: 'b' -}).create(); - -var obj = defaults.compose(newStamp, membership, availability).create(); - - - -// The old constructor / class thing... -var Constructor = function Constructor() { - this.thing = 'initialized'; -}; -Constructor.prototype.foo = function foo() { return 'foo'; }; - -// The conversion -var oldskool = stampit.convertConstructor(Constructor); - -// A new stamp to compose with... -var newskool = stampit().methods({ - bar: function bar() { return 'bar'; } - // your methods here... -}).enclose(function () { - this.baz = 'baz'; -}); - -// Now you can compose those old constructors just like you could -// with any other stamp... -var myThing = stampit.compose(oldskool, newskool); - -var t = myThing(); - -t.thing; // 'initialized', - -t.foo(); // 'foo', - -t.bar(); // 'bar' diff --git a/stampit/stampit-tests.ts b/stampit/stampit-tests.ts index f813482d8..07d3fe858 100644 --- a/stampit/stampit-tests.ts +++ b/stampit/stampit-tests.ts @@ -1,5 +1,6 @@ /// -import stampit = require('./stampit.d'); + +import stampit = require('stampit'); var a = stampit().init((options) => { var a = options.args[0]; diff --git a/stampit/stampit.d.ts b/stampit/stampit.d.ts index e56035c4f..5b03237f2 100644 --- a/stampit/stampit.d.ts +++ b/stampit/stampit.d.ts @@ -294,4 +294,6 @@ declare module stampit { export function convertConstructor(Constructor:any): Stamp; } -export = stampit; +declare module "stampit" { + export = stampit; +}