diff --git a/stories/RenderSequence/index.stories.mdx b/stories/RenderSequence/index.stories.mdx new file mode 100644 index 0000000..ca407d1 --- /dev/null +++ b/stories/RenderSequence/index.stories.mdx @@ -0,0 +1,5 @@ +import Index from './index' + + + + \ No newline at end of file diff --git a/stories/RenderSequence/index.tsx b/stories/RenderSequence/index.tsx new file mode 100644 index 0000000..7a788f8 --- /dev/null +++ b/stories/RenderSequence/index.tsx @@ -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 ( +
+ {React.cloneElement(children, {...rest, location: 'shanghai'})} +
+ ) + } + } +} + +const store = createStore({ + models: {}, +}, applyMiddleware(thunk)) + +export default () => { + const registers = [ + PluginARegister, + PluginBRegister, + PluginCRegister, + PluginDRegister + ] + + return ( + + + + ) +} \ No newline at end of file diff --git a/stories/RenderSequence/plugin-a/index.tsx b/stories/RenderSequence/plugin-a/index.tsx new file mode 100644 index 0000000..b2fc240 --- /dev/null +++ b/stories/RenderSequence/plugin-a/index.tsx @@ -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 ( + + ) +}) \ No newline at end of file diff --git a/stories/RenderSequence/plugin-a/register.ts b/stories/RenderSequence/plugin-a/register.ts new file mode 100644 index 0000000..4abf98a --- /dev/null +++ b/stories/RenderSequence/plugin-a/register.ts @@ -0,0 +1,6 @@ +export default function PluginComponent() { + return { + name: 'plugin-a', + getComponent: () => require('./index'), + }; +} diff --git a/stories/RenderSequence/plugin-b/index.tsx b/stories/RenderSequence/plugin-b/index.tsx new file mode 100644 index 0000000..e69a9ff --- /dev/null +++ b/stories/RenderSequence/plugin-b/index.tsx @@ -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 ( + + ) +}) \ No newline at end of file diff --git a/stories/RenderSequence/plugin-b/register.ts b/stories/RenderSequence/plugin-b/register.ts new file mode 100644 index 0000000..808539c --- /dev/null +++ b/stories/RenderSequence/plugin-b/register.ts @@ -0,0 +1,6 @@ +export default function PluginComponent() { + return { + name: 'plugin-b', + getComponent: () => require('./index'), + }; +} diff --git a/stories/RenderSequence/plugin-c/index.tsx b/stories/RenderSequence/plugin-c/index.tsx new file mode 100644 index 0000000..cf7deb7 --- /dev/null +++ b/stories/RenderSequence/plugin-c/index.tsx @@ -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 ( + + ) +}) \ No newline at end of file diff --git a/stories/RenderSequence/plugin-c/register.ts b/stories/RenderSequence/plugin-c/register.ts new file mode 100644 index 0000000..de007eb --- /dev/null +++ b/stories/RenderSequence/plugin-c/register.ts @@ -0,0 +1,6 @@ +export default function PluginComponent() { + return { + name: 'plugin-c', + getComponent: () => require('./index'), + }; +} diff --git a/stories/RenderSequence/plugin-d/index.tsx b/stories/RenderSequence/plugin-d/index.tsx new file mode 100644 index 0000000..c0f73cd --- /dev/null +++ b/stories/RenderSequence/plugin-d/index.tsx @@ -0,0 +1,14 @@ +import React, { useCallback } from 'react' +import { observe } from '@xhs/relinx' + +export default observe(() => { + const handleClick = useCallback(() => { + alert('finish') + }, []) + + return ( + + ) +}) \ No newline at end of file diff --git a/stories/RenderSequence/plugin-d/register.ts b/stories/RenderSequence/plugin-d/register.ts new file mode 100644 index 0000000..2717ab8 --- /dev/null +++ b/stories/RenderSequence/plugin-d/register.ts @@ -0,0 +1,6 @@ +export default function PluginComponent() { + return { + name: 'plugin-d', + getComponent: () => require('./index'), + }; +}