-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
417 additions
and
40 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
function createUpdater(canvas) { | ||
const setStateQueue = []; | ||
const renderQueue = []; | ||
|
||
function process() { | ||
let item; | ||
let component; | ||
let shouldRender = false; | ||
while ((item = setStateQueue.shift())) { | ||
const { state, component } = item; | ||
|
||
// 如果没有prevState,则将当前的state作为初始的prevState | ||
if (!component.prevState) { | ||
component.prevState = Object.assign({}, component.state); | ||
} | ||
|
||
// 如果stateChange是一个方法,也就是setState的第二种形式 | ||
if (typeof state === "function") { | ||
Object.assign( | ||
component.state, | ||
state(component.prevState, component.props) | ||
); | ||
} else { | ||
// 如果stateChange是一个对象,则直接合并到setState中 | ||
Object.assign(component.state, state); | ||
} | ||
|
||
component.prevState = component.state; | ||
} | ||
|
||
while ((component = renderQueue.shift())) { | ||
component.__shouldRender = true; | ||
component.render(); | ||
shouldRender = true; | ||
} | ||
|
||
if (shouldRender) { | ||
canvas.render(); | ||
} | ||
} | ||
|
||
function enqueueSetState(component, state) { | ||
if (setStateQueue.length === 0) { | ||
setTimeout(process, 0); | ||
} | ||
setStateQueue.push({ | ||
component, | ||
state, | ||
}); | ||
if (renderQueue.indexOf(component) < 0) { | ||
renderQueue.push(component); | ||
} | ||
} | ||
|
||
const updater = { | ||
// isMounted: function(publicInstance) { | ||
// return false; | ||
// }, | ||
// enqueueForceUpdate: function(publicInstance) { | ||
// }, | ||
// enqueueReplaceState: function(publicInstance, completeState) { | ||
// }, | ||
enqueueSetState, | ||
}; | ||
|
||
return updater; | ||
} | ||
|
||
export { createUpdater }; |
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,5 @@ | ||
import withLegend from './withLegend'; | ||
import LegendView from './legendView'; | ||
|
||
export { withLegend, LegendView }; | ||
export default withLegend(LegendView); |
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,51 @@ | ||
import { jsx } from '../../jsx'; | ||
|
||
export default (props) => { | ||
const { items } = props; | ||
return null; | ||
return ( | ||
<group style={{ | ||
left: 50, | ||
top: 50, | ||
width: 100, | ||
flexDirection: 'row' | ||
}}> | ||
{ | ||
items.map(item => { | ||
const { color, name, value } = item; | ||
return ( | ||
<group style={{ flexDirection: 'row', flex: 1, alignItems: 'center', justifyContent: 'center' }}> | ||
<circle | ||
style={{ | ||
width: '20px', | ||
height: '20px', | ||
}} | ||
attrs={{ | ||
fill: color, | ||
r: '6px' | ||
}} | ||
/> | ||
<text | ||
attrs={{ | ||
fill: 'black', | ||
text: item.name, | ||
}} | ||
/> | ||
{ | ||
value ? | ||
<text | ||
attrs={{ | ||
fill: 'black', | ||
text: `: ${value}`, | ||
}} | ||
/> | ||
: | ||
null | ||
} | ||
</group> | ||
) | ||
}) | ||
} | ||
</group> | ||
); | ||
} |
Oops, something went wrong.