Skip to content

Commit

Permalink
feat(edge): add edge.new method to newup isolated template
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Nov 27, 2017
1 parent cbbe629 commit 5db5710
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/Edge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Edge {
*
* @method _getTemplate
*
* @return {Object}
* @return {Template}
*
* @private
*/
Expand All @@ -62,6 +62,17 @@ class Edge {
}, this._globals, this._loader)
}

/**
* Returns a fresh instance of template
*
* @method new
*
* @returns {Template}
*/
new () {
return this._getTemplate()
}

/**
* Registers a new tag. A tag must have following
* attributes.
Expand Down Expand Up @@ -164,42 +175,42 @@ class Edge {
* docblock defined in template renderer
*/
renderString (...args) {
return this._getTemplate().renderString(...args)
return this.new().renderString(...args)
}

/**
* docblock defined in template renderer
*/
compileString (...args) {
return this._getTemplate().compileString(...args)
return this.new().compileString(...args)
}

/**
* docblock defined in template renderer
*/
render (view, ...args) {
return this._getTemplate().render(view, ...args)
return this.new().render(view, ...args)
}

/**
* docblock defined in template renderer
*/
compile (view, ...args) {
return this._getTemplate().compile(view, ...args)
return this.new().compile(view, ...args)
}

/**
* docblock defined in template renderer
*/
presenter (...args) {
return this._getTemplate().presenter(...args)
return this.new().presenter(...args)
}

/**
* docblock defined in template renderer
*/
share (...args) {
return this._getTemplate().share(...args)
return this.new().share(...args)
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/unit/edge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,11 @@ test.group('Edge', (group) => {
const statement = `{{ foo }} {{ bar }}`
assert.equal(sharedInstance.renderString(statement).trim(), 'bar baz')
})

test('edge.new return isolated instance', (assert) => {
const edge = new Edge()
const templ = edge.new()
const templ2 = edge.new()
assert.isFalse(templ === templ2)
})
})

0 comments on commit 5db5710

Please sign in to comment.