-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from chiragpat/rehydration_example
Add support for partial rehydration and example apps for rehydration
- Loading branch information
Showing
19 changed files
with
449 additions
and
157 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
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
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,14 @@ | ||
import { renderComponent } from '@glimmer/core'; | ||
import RehydratingComponent from './src/RehydratingComponent'; | ||
|
||
document.addEventListener( | ||
'DOMContentLoaded', | ||
() => { | ||
const element = document.querySelector('.static-component'); | ||
renderComponent(RehydratingComponent, { | ||
element: element!, | ||
rehydrate: true, | ||
}); | ||
}, | ||
{ once: true } | ||
); |
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,25 @@ | ||
{ | ||
"name": "example-app-partial-rehydration", | ||
"version": "0.1.12", | ||
"description": "Example application using @glimmer packages for partial rehydration", | ||
"main": "dist/commonjs/index.js", | ||
"repository": "https://github.com/glimmerjs/glimmer.js/tree/master/packages/example-apps/partial-rehydration", | ||
"author": "Chirag Patel", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"build": "webpack" | ||
}, | ||
"dependencies": { | ||
"@glimmer/core": "^1.0.0", | ||
"@glimmer/component": "^1.0.0", | ||
"@glimmer/tracking": "^1.0.0", | ||
"@glimmer/helper": "^1.0.0", | ||
"@glimmer/modifier": "^1.0.0", | ||
"@glimmer/ssr": "^1.0.0" | ||
}, | ||
"volta": { | ||
"node": "12.16.1", | ||
"yarn": "1.22.4" | ||
} | ||
} |
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,29 @@ | ||
import { renderToString } from '@glimmer/ssr'; | ||
import StaticComponent from './src/StaticComponent'; | ||
|
||
interface ExpressResponse { | ||
end(str: string): void; | ||
} | ||
|
||
export default async function handler( | ||
_: {}, | ||
res: ExpressResponse, | ||
clientsideBundleLocation: string | ||
): Promise<void> { | ||
const ssrOutput = await renderToString(StaticComponent, { | ||
rehydrate: true, | ||
}); | ||
|
||
res.end(` | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Glimmer Demo</title> | ||
</head> | ||
<body> | ||
<div id="app">${ssrOutput}</div> | ||
<script src="${clientsideBundleLocation}"></script> | ||
</body> | ||
</html> | ||
`); | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/example-apps/partial-rehydration/src/RehydratingComponent.ts
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,24 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { createTemplate, setComponentTemplate } from '@glimmer/core'; | ||
import { on, action } from '@glimmer/modifier'; | ||
|
||
class RehydratingComponent extends Component { | ||
@tracked count = 1; | ||
|
||
@action increment(): void { | ||
this.count++; | ||
} | ||
} | ||
|
||
setComponentTemplate( | ||
createTemplate( | ||
{ on }, | ||
`<p>You have clicked the button {{this.count}} times.</p> | ||
<button {{on "click" this.increment}}>Click</button> | ||
` | ||
), | ||
RehydratingComponent | ||
); | ||
|
||
export default RehydratingComponent; |
16 changes: 16 additions & 0 deletions
16
packages/example-apps/partial-rehydration/src/StaticComponent.ts
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,16 @@ | ||
import { createTemplate, setComponentTemplate, templateOnlyComponent } from '@glimmer/core'; | ||
import RehydratingComponent from './RehydratingComponent'; | ||
|
||
const StaticComponent = setComponentTemplate( | ||
createTemplate( | ||
{ RehydratingComponent }, | ||
`<div class="static-component"> | ||
<h1>Hello I am a static component. I don't change after page load.</h1> | ||
<RehydratingComponent/> | ||
</div> | ||
` | ||
), | ||
templateOnlyComponent() | ||
); | ||
|
||
export default StaticComponent; |
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,14 @@ | ||
import { renderComponent } from '@glimmer/core'; | ||
import MyComponent from './src/MyComponent'; | ||
|
||
document.addEventListener( | ||
'DOMContentLoaded', | ||
() => { | ||
const element = document.getElementById('app'); | ||
renderComponent(MyComponent, { | ||
element: element!, | ||
rehydrate: true, | ||
}); | ||
}, | ||
{ once: true } | ||
); |
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,25 @@ | ||
{ | ||
"name": "example-app-rehydration", | ||
"version": "0.1.12", | ||
"description": "Example application using @glimmer packages for rehydration", | ||
"main": "dist/commonjs/index.js", | ||
"repository": "https://github.com/glimmerjs/glimmer.js/tree/master/packages/example-apps/rehydration", | ||
"author": "Chirag Patel", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"build": "webpack" | ||
}, | ||
"dependencies": { | ||
"@glimmer/core": "^1.0.0", | ||
"@glimmer/component": "^1.0.0", | ||
"@glimmer/tracking": "^1.0.0", | ||
"@glimmer/helper": "^1.0.0", | ||
"@glimmer/modifier": "^1.0.0", | ||
"@glimmer/ssr": "^1.0.0" | ||
}, | ||
"volta": { | ||
"node": "12.16.1", | ||
"yarn": "1.22.4" | ||
} | ||
} |
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,29 @@ | ||
import { renderToString } from '@glimmer/ssr'; | ||
import MyComponent from './src/MyComponent'; | ||
|
||
interface ExpressResponse { | ||
end(str: string): void; | ||
} | ||
|
||
export default async function handler( | ||
_: {}, | ||
res: ExpressResponse, | ||
clientsideBundleLocation: string | ||
): Promise<void> { | ||
const ssrOutput = await renderToString(MyComponent, { | ||
rehydrate: true, | ||
}); | ||
|
||
res.end(` | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Glimmer Demo</title> | ||
</head> | ||
<body> | ||
<div id="app">${ssrOutput}</div> | ||
<script src="${clientsideBundleLocation}"></script> | ||
</body> | ||
</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,24 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { createTemplate, setComponentTemplate } from '@glimmer/core'; | ||
import { on, action } from '@glimmer/modifier'; | ||
|
||
class MyComponent extends Component { | ||
@tracked count = 1; | ||
|
||
@action increment(): void { | ||
this.count++; | ||
} | ||
} | ||
|
||
setComponentTemplate( | ||
createTemplate( | ||
{ on }, | ||
`<p>You have clicked the button {{this.count}} times.</p> | ||
<button {{on "click" this.increment}}>Click</button> | ||
` | ||
), | ||
MyComponent | ||
); | ||
|
||
export default MyComponent; |
Oops, something went wrong.