-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Plugin directive for slot #2619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
29a704c
WIP: plugin param for slot
paulpflug 15072ef
added tests for slot child relations
paulpflug ea2bfaa
added test and first though for v-for behavior
paulpflug 77c359f
some small improvements
paulpflug af2db57
added test for validating plugin child
paulpflug ee98647
cleaned up tests
paulpflug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -2,20 +2,21 @@ import { SLOT } from '../priorities' | |
import { | ||
extractContent, | ||
replace, | ||
remove | ||
remove, | ||
defineReactive | ||
} from '../../util/index' | ||
|
||
export default { | ||
|
||
priority: SLOT, | ||
params: ['name'], | ||
params: ['name','plugin'], | ||
|
||
bind () { | ||
// this was resolved during component transclusion | ||
var name = this.params.name || 'default' | ||
var content = this.vm._slotContents && this.vm._slotContents[name] | ||
if (!content || !content.hasChildNodes()) { | ||
this.fallback() | ||
this.compile(extractContent(this.el, true), this.vm) | ||
} else { | ||
this.compile(content.cloneNode(true), this.vm._context, this.vm) | ||
} | ||
|
@@ -38,12 +39,52 @@ export default { | |
elseBlock._context = this.vm | ||
content.appendChild(elseBlock) | ||
} | ||
const scope = host | ||
let scope = host | ||
? host._scope | ||
: this._scope | ||
this.unlink = context.$compile( | ||
content, host, scope, this._frag | ||
) | ||
|
||
if (this.params.plugin) { | ||
if (!host) { | ||
// TODO warn to use plugin only within components | ||
} | ||
// copy all remaining attributes from slot to all direct children | ||
let attrs = this.el.attributes | ||
for(let i = attrs.length - 1; i >= 0; i--) { | ||
let name = attrs[i].name, | ||
value = attrs[i].value, | ||
children = content.children | ||
for(let j = 0, len = children.length; j < len; j++) { | ||
// TODO warn if child can't have attributes? | ||
if (!(children[j].hasAttribute(name) || | ||
(name[0]===':' && children[j].hasAttribute('v-bind'+name)) || | ||
(name[0]==='@' && children[j].hasAttribute('v-on:'+name.slice(1))) | ||
)) { | ||
children[j].setAttribute(name,value) | ||
} | ||
} | ||
} | ||
// use v-for scope when available | ||
scope = this._frag ? this._frag.scope : scope || {} | ||
|
||
// add all data from context to scope | ||
for(let data in context._data) { | ||
if (scope[data] == null) { | ||
defineReactive(scope,data,context._data[data]) | ||
} | ||
} | ||
// add all data from host to scope with prefixed names | ||
for(let data in host._data) { | ||
defineReactive(scope,'_'+data,host._data[data]) | ||
} | ||
// child relations test: how to get the slot content to be comp11 child? | ||
this.unlink = context.$compile(content, host, scope, this._frag) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't find I don't understand it, yet.. |
||
if (this.params.plugin !== true) { | ||
// should check on the newly created vm if it is valid | ||
} | ||
|
||
} else { | ||
this.unlink = context.$compile(content, host, scope, this._frag) | ||
} | ||
} | ||
if (content) { | ||
replace(this.el, content) | ||
|
@@ -52,10 +93,6 @@ export default { | |
} | ||
}, | ||
|
||
fallback () { | ||
this.compile(extractContent(this.el, true), this.vm) | ||
}, | ||
|
||
unbind () { | ||
if (this.unlink) { | ||
this.unlink() | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
best way I can think of to avoid naming conflict of context and host.
Forces the user of
plugin
to prefix the variables in his markup when using slotBut the functionality outweighs the inconsistency (and it is hidden from the user, as it should be)