Skip to content

Commit

Permalink
feat(components): components can now pass data to the slots
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 7, 2018
1 parent fd884ea commit 4edb22e
Show file tree
Hide file tree
Showing 20 changed files with 377 additions and 68 deletions.
4 changes: 2 additions & 2 deletions fixtures/components-named-slots/alert.edge
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{ $slots.heading }}
{{ $slots.main }}
{{ $slots.heading() }}
{{ $slots.main() }}
10 changes: 10 additions & 0 deletions fixtures/components-named-slots/compiled.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
(function (template, ctx) {
let out = ''
out += template.renderWithState('components-named-slots/alert', {}, { 'heading': (function (template, ctx) {
return function (props) {
let out = ''
ctx.newFrame()
ctx.setOnFrame('props', props)
out += ' This is title'
out += '\n'
ctx.removeFrame()
return out
}
})(template, ctx), 'main': (function (template, ctx) {
return function (props) {
let out = ''
ctx.newFrame()
ctx.setOnFrame('props', props)
out += ' This is then body'
out += '\n'
ctx.removeFrame()
return out
}
})(template, ctx) })
return out
})(template, ctx)
2 changes: 1 addition & 1 deletion fixtures/components-props/alert.edge
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{ title }}
{{ $slots.main }}
{{ $slots.main() }}
5 changes: 5 additions & 0 deletions fixtures/components-props/compiled.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
(function (template, ctx) {
let out = ''
out += template.renderWithState('components-props/alert', { 'title': 'H1' }, { 'main': (function (template, ctx) {
return function (props) {
let out = ''
ctx.newFrame()
ctx.setOnFrame('props', props)
out += 'Hello world'
out += '\n'
ctx.removeFrame()
return out
}
})(template, ctx) })
return out
})(template, ctx)
2 changes: 2 additions & 0 deletions fixtures/components-slot-props/alert.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Top level username is {{ username || 'Guest' }}
{{ $slots.title({ username: 'nikk' }) }}
16 changes: 16 additions & 0 deletions fixtures/components-slot-props/compiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(function (template, ctx) {
let out = ''
out += template.renderWithState('components-slot-props/alert', {}, { 'title': (function (template, ctx) {
return function (props) {
let out = ''
ctx.newFrame()
ctx.setOnFrame('props', props)
out += ' Hello '
out += `${ctx.escape(ctx.resolve('props').username)}`
out += '\n'
ctx.removeFrame()
return out
}
})(template, ctx) })
return out
})(template, ctx)
5 changes: 5 additions & 0 deletions fixtures/components-slot-props/index.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@component('components-slot-props/alert')
@slot('title')
Hello {{ props.username }}
@endslot
@endcomponent
3 changes: 3 additions & 0 deletions fixtures/components-slot-props/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"username": "virk"
}
2 changes: 2 additions & 0 deletions fixtures/components-slot-props/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Top level username is Guest
Hello nikk
2 changes: 1 addition & 1 deletion fixtures/components-state/alert.edge
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ $slots.main }}
{{ $slots.main() }}
5 changes: 5 additions & 0 deletions fixtures/components-state/compiled.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
(function (template, ctx) {
let out = ''
out += template.renderWithState('components-state/alert', {}, { 'main': (function (template, ctx) {
return function (props) {
let out = ''
ctx.newFrame()
ctx.setOnFrame('props', props)
out += ' Hello '
out += `${ctx.escape(ctx.resolve('username'))}`
out += '\n'
ctx.removeFrame()
return out
}
})(template, ctx) })
return out
})(template, ctx)
2 changes: 1 addition & 1 deletion fixtures/components/alert.edge
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ $slots.main }}
{{ $slots.main() }}
5 changes: 5 additions & 0 deletions fixtures/components/compiled.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
(function (template, ctx) {
let out = ''
out += template.renderWithState('components/alert', {}, { 'main': (function (template, ctx) {
return function (props) {
let out = ''
ctx.newFrame()
ctx.setOnFrame('props', props)
out += ' Hello world'
out += '\n'
ctx.removeFrame()
return out
}
})(template, ctx) })
return out
})(template, ctx)
2 changes: 1 addition & 1 deletion japaFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Assertion.use((chai, utils) => {
}
})

cli.run('test/edge.spec.ts')
cli.run('test/*.spec.ts')
Loading

0 comments on commit 4edb22e

Please sign in to comment.