-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 🎸 @props field update via set method * chore: 🤖 upgrade all dependencies * chore: 🤖 change bundlesize * refactor: 💡 eslint fix * chore: buid:r error * chore: integration with yarn-deduplicate Co-authored-by: JounQin <admin@1stg.me>
- Loading branch information
Showing
23 changed files
with
3,084 additions
and
2,873 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
"newline-after-var": [ | ||
"warn", | ||
"always" | ||
] | ||
], | ||
"unicorn/filename-case": 0 | ||
} | ||
} |
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<title>Playground</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script src="./dev.tsx"></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,8 @@ | ||
import 'reflect-metadata'; | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
import { DevApp } from './src/Dev'; | ||
|
||
ReactDOM.render(<DevApp />, document.querySelector('#root')); |
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,15 +1,15 @@ | ||
import React from 'react'; | ||
|
||
import { Counter } from './components/Counter'; | ||
import { CounterSpeed } from './components/Counter'; | ||
|
||
import { StatedBeanApplication, StatedBeanProvider } from 'stated-bean'; | ||
|
||
const app = new StatedBeanApplication(); | ||
|
||
export const Test = () => { | ||
export const DevApp = () => { | ||
return ( | ||
<StatedBeanProvider application={app}> | ||
<Counter value={10} /> | ||
<CounterSpeed /> | ||
</StatedBeanProvider> | ||
); | ||
}; |
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,32 +1,34 @@ | ||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
import React from 'react'; | ||
|
||
import { CounterModel } from '../../models/CounterModel'; | ||
import { CounterModel } from './model'; | ||
|
||
import { useBean } from 'stated-bean'; | ||
|
||
export interface CounterProps { | ||
value: number; | ||
speed?: number; | ||
} | ||
|
||
// const CounterModel = { | ||
// count: 10, | ||
// decrement() { | ||
// this.count--; | ||
// }, | ||
// increment() { | ||
// this.count++; | ||
// }, | ||
// }; | ||
export function Counter(props: CounterProps = { speed: 1 }) { | ||
const counter = useBean(CounterModel, { props }); | ||
|
||
export function Counter(props: CounterProps) { | ||
const counter = useBean(() => new CounterModel(), { props }); | ||
return <span>Count: {counter.count}</span>; | ||
} | ||
|
||
export function CounterSpeed() { | ||
const [speed, setSpeed] = React.useState(1); | ||
|
||
return ( | ||
<div> | ||
<button onClick={counter.decrement}>-</button> | ||
<span>{counter.count}</span> | ||
<button onClick={counter.increment}>+</button> | ||
<div style={{ margin: '50px auto', display: 'flex', justifyContent: 'center' }}> | ||
<span>Speed: </span> | ||
<input | ||
type="number" | ||
value={speed} | ||
onChange={e => { | ||
setSpeed(Number(e.target.value)); | ||
}} | ||
/> | ||
<Counter speed={speed} /> | ||
</div> | ||
); | ||
} |
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,32 @@ | ||
import { InitializingBean, Props, Stated, StatedBean } from 'stated-bean'; | ||
|
||
@StatedBean({ singleton: false }) | ||
export class CounterModel implements InitializingBean { | ||
@Stated() | ||
count = 0; | ||
|
||
@Props() | ||
speed = 1; | ||
|
||
timer?: NodeJS.Timeout; | ||
|
||
afterProvided() { | ||
this.startTimer(1); | ||
} | ||
|
||
startTimer(speed: number) { | ||
if (this.timer) { | ||
clearInterval(this.timer); | ||
} | ||
|
||
this.timer = setInterval(() => { | ||
this.count++; | ||
}, 1000 * (1 / speed)); | ||
} | ||
|
||
setSpeed(speed: number) { | ||
if (speed > 0) { | ||
this.startTimer(speed); | ||
} | ||
} | ||
} |
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
6 changes: 3 additions & 3 deletions
6
example/src/models/TodoModel.ts → example/src/components/Todo/model.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
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
/* istanbul ignore file */ | ||
|
||
function is(x: unknown, y: unknown): boolean { | ||
// SameValue algorithm | ||
if (x === y) { | ||
// Steps 1-5, 7-10 | ||
// Steps 6.b-6.e: +0 != -0 | ||
// Added the nonzero y check to make Flow happy, but it is redundant | ||
return x !== 0 || y !== 0 || 1 / x === 1 / y; | ||
} else { | ||
// Step 6.a: NaN == NaN | ||
// eslint-disable-next-line no-self-compare | ||
return x !== x && y !== y; | ||
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function shallowEqual(objA: any, objB: any): boolean { | ||
if (is(objA, objB)) { | ||
return true; | ||
} | ||
|
||
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { | ||
return false; | ||
} | ||
|
||
const keysA = Object.keys(objA); | ||
const keysB = Object.keys(objB); | ||
|
||
if (keysA.length !== keysB.length) { | ||
return false; | ||
} | ||
|
||
// Test for A's keys different from B. | ||
for (const element of keysA) { | ||
if (!Object.prototype.hasOwnProperty.call(objB, element) || !is(objA[element], objB[element])) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
export { shallowEqual }; |
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
Oops, something went wrong.