-
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.
close #26, add render sequence examples
- Loading branch information
Showing
10 changed files
with
195 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Index from './index' | ||
|
||
<Meta title="Usage/render-sequence" /> | ||
|
||
<Index /> |
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,107 @@ | ||
import React from 'react'; | ||
import { applyMiddleware, createStore, thunk, Provider } from '@xhs/relinx' | ||
import { Halation } from '../../src' | ||
|
||
import PluginARegister from './plugin-a/register' | ||
import PluginBRegister from './plugin-b/register' | ||
import PluginCRegister from './plugin-c/register' | ||
import PluginDRegister from './plugin-d/register' | ||
|
||
const halationState = [{ | ||
name: 'plugin-a', | ||
key: 'plugin-a-1', | ||
prevSibling: null, | ||
nextSibling: 'plugin-b-1', | ||
children: [], | ||
type: 'block', | ||
}, { | ||
name: 'plugin-b', | ||
key: 'plugin-b-1', | ||
prevSibling: 'plugin-a-1', | ||
nextSibling: 'plugin-c-1', | ||
children: [], | ||
type: 'block', | ||
strategies: [{ | ||
type: 'event', | ||
resolver: ({ event }) => { | ||
const { pluginBVisible } = event | ||
return !!pluginBVisible | ||
} | ||
}] | ||
}, { | ||
name: 'plugin-c', | ||
key: 'plugin-c-1', | ||
prevSibling: 'plugin-b-1', | ||
nextSibling: 'plugin-d-1', | ||
children: [], | ||
type: 'block', | ||
strategies: [{ | ||
type: 'event', | ||
resolver: ({ event }) => { | ||
const { pluginCVisible } = event | ||
return !!pluginCVisible | ||
} | ||
}] | ||
}, { | ||
name: 'plugin-d', | ||
key: 'plugin-d-1', | ||
prevSibling: 'plugin-c-1', | ||
nextSibling: null, | ||
children: [], | ||
type: 'block', | ||
strategies: [{ | ||
type: 'event', | ||
resolver: ({ event }) => { | ||
const { pluginDVisible } = event | ||
return !!pluginDVisible | ||
} | ||
}] | ||
}] | ||
|
||
const blockRenderFn = blockProps => { | ||
const { type } = blockProps | ||
|
||
if (type === 'block') { | ||
return props => { | ||
const { children, ...rest } = props | ||
return ( | ||
<div className="block-render-fn"> | ||
{React.cloneElement(children, {...rest, location: 'shanghai'})} | ||
</div> | ||
) | ||
} | ||
} | ||
} | ||
|
||
const store = createStore({ | ||
models: {}, | ||
}, applyMiddleware(thunk)) | ||
|
||
export default () => { | ||
const registers = [ | ||
PluginARegister, | ||
PluginBRegister, | ||
PluginCRegister, | ||
PluginDRegister | ||
] | ||
|
||
return ( | ||
<Provider | ||
store={store} | ||
> | ||
<Halation | ||
name='super' | ||
halationState={halationState} | ||
registers={registers} | ||
blockRenderFn={blockRenderFn} | ||
store={store} | ||
events={{ | ||
pluginAVisible: true, | ||
pluginBVisible: false, | ||
pluginCVisible: false, | ||
pluginDVisible: false, | ||
}} | ||
/> | ||
</Provider> | ||
) | ||
} |
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,15 @@ | ||
import React, { useCallback } from 'react' | ||
import { observe } from '@xhs/relinx' | ||
|
||
export default observe((props) => { | ||
const { dispatchEvent } = props | ||
const handleClick = useCallback(() => { | ||
dispatchEvent('pluginBVisible') | ||
}, []) | ||
|
||
return ( | ||
<button onClick={handleClick}> | ||
trigger plugin-b render | ||
</button> | ||
) | ||
}) |
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,6 @@ | ||
export default function PluginComponent() { | ||
return { | ||
name: 'plugin-a', | ||
getComponent: () => require('./index'), | ||
}; | ||
} |
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,15 @@ | ||
import React, { useCallback } from 'react' | ||
import { observe } from '@xhs/relinx' | ||
|
||
export default observe((props) => { | ||
const { dispatchEvent } = props | ||
const handleClick = useCallback(() => { | ||
dispatchEvent('pluginCVisible') | ||
}, []) | ||
|
||
return ( | ||
<button onClick={handleClick}> | ||
trigger plugin-c render | ||
</button> | ||
) | ||
}) |
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,6 @@ | ||
export default function PluginComponent() { | ||
return { | ||
name: 'plugin-b', | ||
getComponent: () => require('./index'), | ||
}; | ||
} |
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,15 @@ | ||
import React, { useCallback } from 'react' | ||
import { observe } from '@xhs/relinx' | ||
|
||
export default observe((props) => { | ||
const { dispatchEvent } = props | ||
const handleClick = useCallback(() => { | ||
dispatchEvent('pluginDVisible') | ||
}, []) | ||
|
||
return ( | ||
<button onClick={handleClick}> | ||
trigger plugin-d render | ||
</button> | ||
) | ||
}) |
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,6 @@ | ||
export default function PluginComponent() { | ||
return { | ||
name: 'plugin-c', | ||
getComponent: () => require('./index'), | ||
}; | ||
} |
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 React, { useCallback } from 'react' | ||
import { observe } from '@xhs/relinx' | ||
|
||
export default observe(() => { | ||
const handleClick = useCallback(() => { | ||
alert('finish') | ||
}, []) | ||
|
||
return ( | ||
<button onClick={handleClick}> | ||
finish | ||
</button> | ||
) | ||
}) |
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,6 @@ | ||
export default function PluginComponent() { | ||
return { | ||
name: 'plugin-d', | ||
getComponent: () => require('./index'), | ||
}; | ||
} |