Skip to content

Commit

Permalink
Merge branch 'release/2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Feb 2, 2019
2 parents 9eff6e7 + 2c575cf commit 2177dc7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="2.0.1"></a>
## [2.0.1](https://github.com/poppinss/macroable/compare/2.0.0...2.0.1) (2019-02-02)


### Features

* **macroable:** expose static interface ([f3720ce](https://github.com/poppinss/macroable/commit/f3720ce))



<a name="2.0.0"></a>
# 2.0.0 (2018-10-28)

Expand Down
22 changes: 14 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
* file that was distributed with this source code.
*/

type IMacroableFn = (...args: []) => any
type IMacroableMap = { [key: string]: IMacroableFn }
type MacroableFn = (...args: []) => any
type MacroableMap = { [key: string]: MacroableFn }

export interface MacroableConstructorContract {
macro (name: string, callback: MacroableFn),
getter (name: string, callback: MacroableFn, singleton?: boolean),
hydrate (),
}

/**
* Macroable is an abstract class to add ability to extend your class
Expand All @@ -22,8 +28,8 @@ type IMacroableMap = { [key: string]: IMacroableFn }
* 2. Can define singleton getters.
*/
export abstract class Macroable {
protected static _macros: IMacroableMap = {}
protected static _getters: IMacroableMap = {}
protected static _macros: MacroableMap = {}
protected static _getters: MacroableMap = {}

/**
* Add a macro to the class. This method is a better to manually adding
Expand All @@ -38,15 +44,15 @@ export abstract class Macroable {
* })
* ```
*/
public static macro (name: string, callback: IMacroableFn) {
public static macro (name: string, callback: MacroableFn) {
this._macros[name] = callback
this.prototype[name] = callback
}

/**
* Return the existing macro or null if it doesn't exists
*/
public static getMacro (name: string): IMacroableFn | undefined {
public static getMacro (name: string): MacroableFn | undefined {
return this._macros[name]
}

Expand Down Expand Up @@ -77,7 +83,7 @@ export abstract class Macroable {
* console.log(new Macroable().time)
* ```
*/
public static getter (name: string, callback: IMacroableFn, singleton: boolean = false) {
public static getter (name: string, callback: MacroableFn, singleton: boolean = false) {
const wrappedCallback = singleton ? function wrappedCallback () {
const propName = `_${name}_`
this[propName] = this[propName] || callback.bind(this)()
Expand All @@ -96,7 +102,7 @@ export abstract class Macroable {
/**
* Return the existing getter or null if it doesn't exists
*/
public static getGetter (name: string): IMacroableFn | undefined {
public static getGetter (name: string): MacroableFn | undefined {
return this._getters[name]
}

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "macroable",
"version": "2.0.0",
"version": "2.0.1",
"description": "A simple ES6 class that can be extended to provide macros and getters functionality",
"main": "build/index.js",
"files": [
Expand All @@ -25,20 +25,20 @@
"author": "amanvirk,adonisjs",
"license": "MIT",
"devDependencies": {
"@adonisjs/mrm-preset": "^1.0.14",
"@types/node": "^10.12.0",
"commitizen": "^3.0.4",
"@adonisjs/mrm-preset": "^1.0.16",
"@types/node": "^10.12.21",
"commitizen": "^3.0.5",
"coveralls": "^3.0.2",
"cz-conventional-changelog": "^2.1.0",
"del-cli": "^1.1.0",
"japa": "^2.0.6",
"japa": "^2.0.7",
"mrm": "^1.2.1",
"nyc": "^13.1.0",
"pkg-ok": "^2.3.1",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"ts-node": "^8.0.2",
"tslint": "^5.12.1",
"tslint-eslint-rules": "^5.4.0",
"typescript": "^3.1.3",
"typescript": "^3.3.1",
"yorkie": "^2.0.0"
},
"dependencies": {
Expand Down

0 comments on commit 2177dc7

Please sign in to comment.