diff --git a/src/Template/index.js b/src/Template/index.js index a9b67a5..e686db7 100644 --- a/src/Template/index.js +++ b/src/Template/index.js @@ -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) } @@ -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 } diff --git a/test/unit/tags/component.spec.js b/test/unit/tags/component.spec.js index 899ef10..3281085 100644 --- a/test/unit/tags/component.spec.js +++ b/test/unit/tags/component.spec.js @@ -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') - }) })