From 147b725f10f9d8984a383e7617bba062ea33e392 Mon Sep 17 00:00:00 2001 From: Cuttle Cong Date: Fri, 2 Mar 2018 22:25:57 +0800 Subject: [PATCH] refactor: add RouterContext --- srcPackages/RouterContextV3.js | 45 ++++++++++++++++++++++++++++++++++ srcPackages/RouterV3.js | 33 ++++--------------------- 2 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 srcPackages/RouterContextV3.js diff --git a/srcPackages/RouterContextV3.js b/srcPackages/RouterContextV3.js new file mode 100644 index 0000000..4cb28de --- /dev/null +++ b/srcPackages/RouterContextV3.js @@ -0,0 +1,45 @@ +/** + * @file Router + * @author Cuttle Cong + * @date 2018/1/27 + * @description + */ +import * as React from 'react' +import { h } from '../' +import { RouterContext } from 'react-router' + +/** + * 如果你依赖了 **react-router v3**,那么可以使用该 RouterContext 定义,而不是 react-router 的 RouterContext + * **注意**: 请用以下方式引入 + * `import RouterContext from 'react-mobx-vm/packages/RouterContextV3'` + * @public + * @name RouterContext + */ +export default function RouterContextV3({ components, createElement, ...props }) { + createElement = createElement || h + if (components) { + components = components.map(comp => { + if (comp && typeof comp === 'object') { + const f = () => { + } + f['__[[actual]]__'] = comp + return f + } + return comp + }) + } + + return ( + + ) +} diff --git a/srcPackages/RouterV3.js b/srcPackages/RouterV3.js index a7241f7..562ce3e 100644 --- a/srcPackages/RouterV3.js +++ b/srcPackages/RouterV3.js @@ -6,43 +6,20 @@ */ import * as React from 'react' import { h } from '../' -import { RouterContext, Router } from 'react-router' - +import { Router } from 'react-router' +import RouterContext from './RouterContextV3' /** - * 如果你依赖了 **react-router v3**,那么可以使用该 Router 定义,而不是 react-router 的 Router + * 如果你依赖了 **react-router v3**,那么可以使用该 Router 定义,而不是 react-router 的 Router * **注意**: 请用以下方式引入 * `import Router from 'react-mobx-vm/packages/RouterV3'` * @public * @name Router */ export default function VMRouter(props = {}) { - const createElement = props.createElement || h - function render(props) { - const components = props.components.map(comp => { - if (comp && typeof comp === 'object') { - const f = () => { - } - f['__[[actual]]__'] = comp - return f - } - return comp - }) - return ( - - ) + return } - return + return }