-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
two-way component binding in SSR
- Loading branch information
Showing
13 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,12 +1,19 @@ | ||
export default { | ||
enter ( generator, node ) { | ||
const { snippet } = generator.contextualise( node.expression ); | ||
|
||
generator.append( '${ ' + snippet + ' ? `' ); | ||
|
||
generator.push({ | ||
conditions: generator.current.conditions.concat( snippet ) | ||
}); | ||
}, | ||
|
||
leave ( generator, node ) { | ||
generator.append( '` : `' ); | ||
if ( node.else ) node.else.children.forEach( child => generator.visit( child ) ); | ||
generator.append( '` }' ); | ||
|
||
generator.pop(); | ||
} | ||
}; |
This file contains 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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { compile } from '../index.js'; | ||
|
||
function capitalise ( name ) { | ||
return name[0].toUpperCase() + name.slice( 1 ); | ||
} | ||
|
||
require.extensions[ '.html' ] = function ( module, filename ) { | ||
const { code } = compile( fs.readFileSync( filename, 'utf-8' ), { | ||
filename, | ||
name: capitalise( path.basename( filename ).replace( /\.html$/, '' ) ), | ||
generate: 'ssr' | ||
}); | ||
|
||
return module._compile( code, filename ); | ||
}; |
11 changes: 11 additions & 0 deletions
11
test/server-side-rendering/component-binding-renamed/Foo.html
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
:foo: | ||
|
||
<script> | ||
export default { | ||
data () { | ||
return { | ||
x: 1 | ||
}; | ||
} | ||
}; | ||
</script> |
1 change: 1 addition & 0 deletions
1
test/server-side-rendering/component-binding-renamed/_actual.html
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
1:foo:1 |
1 change: 1 addition & 0 deletions
1
test/server-side-rendering/component-binding-renamed/_expected.html
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
1:foo:1 |
11 changes: 11 additions & 0 deletions
11
test/server-side-rendering/component-binding-renamed/main.html
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{y}}<Foo bind:y='x'/>{{y}} | ||
|
||
<script> | ||
import Foo from './Foo.html'; | ||
|
||
export default { | ||
components: { | ||
Foo | ||
} | ||
}; | ||
</script> |
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
:foo: | ||
|
||
<script> | ||
export default { | ||
data () { | ||
return { | ||
x: 1 | ||
}; | ||
} | ||
}; | ||
</script> |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
1:foo:1 |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
1:foo:1 |
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{x}}<Foo bind:x/>{{x}} | ||
|
||
<script> | ||
import Foo from './Foo.html'; | ||
|
||
export default { | ||
components: { | ||
Foo | ||
} | ||
}; | ||
</script> |