-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[optimize] simplify Example Code with Function & Class components
- Loading branch information
Showing
4 changed files
with
51 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import { component, mixin, watch, createCell } from 'web-cell'; | ||
|
||
@component({ | ||
tagName: 'cell-clock' | ||
}) | ||
export class CellClock extends mixin() { | ||
@watch | ||
time = new Date(); | ||
|
||
private timer: number; | ||
|
||
connectedCallback() { | ||
this.timer = self.setInterval(() => (this.time = new Date()), 1000); | ||
} | ||
|
||
disconnectedCallback() { | ||
clearInterval(this.timer); | ||
} | ||
|
||
render() { | ||
const { time } = this; | ||
|
||
return <div>{time.toLocaleString()}</div>; | ||
} | ||
} | ||
import { observable } from 'mobx'; | ||
import { component, observer } from 'web-cell'; | ||
|
||
@component({ tagName: 'cell-clock' }) | ||
@observer | ||
export class CellClock extends HTMLElement { | ||
@observable | ||
accessor time = new Date(); | ||
|
||
private timer: number; | ||
|
||
connectedCallback() { | ||
this.timer = self.setInterval(() => (this.time = new Date()), 1000); | ||
} | ||
|
||
disconnectedCallback() { | ||
clearInterval(this.timer); | ||
} | ||
|
||
render() { | ||
const { time } = this; | ||
|
||
return <time dateTime={time.toJSON()}>{time.toLocaleString()}</time>; | ||
} | ||
} |
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,5 +1,3 @@ | ||
import { createCell } from 'web-cell'; | ||
|
||
export function Hello({ name = 'World' }) { | ||
return <h1>Hello, {name}!</h1>; | ||
} | ||
export function Hello({ name = 'World' }) { | ||
return <h1>Hello, {name}!</h1>; | ||
} |
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,38 +1,21 @@ | ||
import { configure, observable } from 'mobx'; | ||
import { component, observer } from 'web-cell'; | ||
import { CellClock } from './Clock'; | ||
import { Hello } from './Hello'; | ||
|
||
configure({ enforceActions: 'never' }); | ||
|
||
@component({ tagName: 'home-page' }) | ||
@observer | ||
export class HomePage extends HTMLElement { | ||
@observable | ||
accessor time = ''; | ||
|
||
connectedCallback() { | ||
setInterval(() => (this.time = new Date().toLocaleString()), 1000); | ||
} | ||
|
||
render() { | ||
const { time } = this; | ||
|
||
return ( | ||
<> | ||
<h1>Hello Vanilla!</h1> | ||
<div> | ||
We use the same configuration as Parcel to bundle this | ||
sandbox, you can find more info about Parcel | ||
<a | ||
href="https://parceljs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
here | ||
</a> | ||
. | ||
</div> | ||
<time>{time}</time> | ||
</> | ||
); | ||
} | ||
} | ||
export const HomePage = () => ( | ||
<> | ||
<Hello name="WebCell" /> | ||
<div> | ||
We use the same configuration as Parcel to bundle this sandbox, you | ||
can find more info about Parcel{' '} | ||
<a | ||
href="https://parceljs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
here | ||
</a> | ||
. | ||
</div> | ||
<CellClock /> | ||
</> | ||
); |
bc17cb0
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.
Deploy preview for web-cell-scaffold ready!
✅ Preview
https://web-cell-scaffold-owm2gijcu-techquery.vercel.app
Built with commit bc17cb0.
This pull request is being automatically deployed with vercel-action