Skip to content

Commit

Permalink
revert(component): remove option to share data with component
Browse files Browse the repository at this point in the history
components should be isolated, the idea of optionally sharing the data is dirty. So removed it
  • Loading branch information
thetutlage committed Oct 26, 2017
1 parent a6735fc commit 83c57e5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
10 changes: 1 addition & 9 deletions src/Template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,10 @@ class Template {
* Convert props array to data object
*/
let presenter = null
let shareData = false

const data = _.transform(props, (result, prop) => {
if (prop.presenter) {
presenter = prop.presenter
} else if (prop.shareData) {
shareData = true
} else {
_.merge(result, prop)
}
Expand All @@ -427,13 +424,8 @@ class Template {

const template = new Template(this._tags, this._options, this._globals, this._loader)
template.presenter(presenter)
template._makeContext(data)

if (shareData) {
debug('sharing parent template data with component')
template._makeContext(_.assign({}, this.context.$presenter.$data, data))
} else {
template._makeContext(data)
}
return template
}

Expand Down
26 changes: 0 additions & 26 deletions test/unit/tags/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,30 +348,4 @@ test.group('Tags | Component ', (group) => {
const $ = cheerio.load(output)
assert.equal($('h2').text().trim(), '1')
})

test('share data from the parent view', (assert) => {
const template = new Template(this.tags, {}, {
size: function (dict) { return dict.length }
}, loader)
const statement = dedent`
@!component('components.access-globals', shareData = true)
`
this.tags.each.run(Context)
const output = template.renderString(statement, { users: ['virk', 'nikk'] })
const $ = cheerio.load(output)
assert.equal($('h2').text().trim(), '2')
})

test('should override the parent data view', (assert) => {
const template = new Template(this.tags, {}, {
size: function (dict) { return dict.length }
}, loader)
const statement = dedent`
@!component('components.access-globals', shareData = true, users = ['virk'])
`
this.tags.each.run(Context)
const output = template.renderString(statement, { users: ['virk', 'nikk'] })
const $ = cheerio.load(output)
assert.equal($('h2').text().trim(), '1')
})
})

0 comments on commit 83c57e5

Please sign in to comment.