-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] rewrite Function Observer adapter
- Loading branch information
Showing
6 changed files
with
143 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
.eslintrc.json | ||
jest.config.ts | ||
test/ | ||
preview/ | ||
.parcel-cache/ | ||
Contributing.md | ||
docs/ | ||
.husky/ | ||
.github/ | ||
.vscode/ | ||
.vscode/ | ||
.vercel/ |
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,40 @@ | ||
import { observable } from 'mobx'; | ||
import { Second } from 'web-utility'; | ||
import { component, observer } from '../source'; | ||
|
||
class ClockModel { | ||
@observable | ||
accessor time = new Date(); | ||
|
||
constructor() { | ||
setInterval(() => (this.time = new Date()), Second); | ||
} | ||
} | ||
|
||
const clockStore = new ClockModel(); | ||
|
||
export const FunctionClock = observer(() => { | ||
const { time } = clockStore; | ||
|
||
return ( | ||
<time dateTime={time.toJSON()}> | ||
Function Clock: {time.toLocaleString()} | ||
</time> | ||
); | ||
}); | ||
|
||
@component({ tagName: 'class-clock' }) | ||
@observer | ||
export class ClassClock extends HTMLElement { | ||
state = new ClockModel(); | ||
|
||
render() { | ||
const { time } = this.state; | ||
|
||
return ( | ||
<time dateTime={time.toJSON()}> | ||
Class Clock: {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,38 +1,27 @@ | ||
import { configure, observable } from 'mobx'; | ||
import { component, observer } from '../source'; | ||
import { ClassClock, FunctionClock } from './Clock'; | ||
|
||
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 = () => ( | ||
<> | ||
<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> | ||
<ul> | ||
<li> | ||
<FunctionClock /> | ||
</li> | ||
<li> | ||
<ClassClock /> | ||
</li> | ||
</ul> | ||
</> | ||
); |
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,8 @@ | ||
import { DOMRenderer } from 'dom-renderer'; | ||
import { configure } from 'mobx'; | ||
|
||
import { HomePage } from './Home'; | ||
|
||
configure({ enforceActions: 'never' }); | ||
|
||
new DOMRenderer().render(<HomePage />, document.querySelector('#app')!); |
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
1c22770
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 ready!
✅ Preview
https://web-cell-1bi48ds0d-techquery.vercel.app
Built with commit 1c22770.
This pull request is being automatically deployed with vercel-action