-
Notifications
You must be signed in to change notification settings - Fork 304
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
8 changed files
with
239 additions
and
138 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
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
Large diffs are not rendered by default.
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
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,29 @@ | ||
/** | ||
* Comment Factory Abstraction | ||
* | ||
* @author Jim Chen | ||
* @license MIT License | ||
* @description Factory to allow creation of different kinds of comments with | ||
* different underlying abstractions. | ||
*/ | ||
/// <reference path="Core.d.ts" /> | ||
interface ICommentFactory { | ||
(comment:Object):IComment; | ||
} | ||
class CommentFactory { | ||
private _bindings:{[key:number]:ICommentFactory;} = {}; | ||
|
||
public bind (mode:number, factory:ICommentFactory):void { | ||
this._bindings[mode] = factory; | ||
} | ||
|
||
public create (comment:Object):IComment { | ||
if (comment === null || !comment.hasOwnProperty('mode')) { | ||
throw new Error('Comment format incorrect'); | ||
} | ||
if (!this._bindings.hasOwnProperty(comment.mode)) { | ||
throw new Error('No binding for comment type ' + comment.mode); | ||
} | ||
return this._bindings[comment.mode](comment); | ||
} | ||
} |
Oops, something went wrong.