From 70fcde33f9fe260ba5be98a1c08771ce1163e053 Mon Sep 17 00:00:00 2001 From: MO <9125255+fengzilong@users.noreply.github.com> Date: Tue, 31 Aug 2021 12:29:06 +0800 Subject: [PATCH 1/2] feat: support customize styles and scripts --- packages/rax-document/src/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/rax-document/src/index.js b/packages/rax-document/src/index.js index 072256a55..ed2ead337 100644 --- a/packages/rax-document/src/index.js +++ b/packages/rax-document/src/index.js @@ -46,12 +46,22 @@ function Data(props, context) { // Named by role rather than implementationm, so component name are `Style` rather than `Styles`. function Style(props, context) { const { __styles = [] } = context; + const consumer = getConsumer(props); + + if (typeof consumer === 'function') { + return consumer(__styles); + } return __styles.map((src, index) => ); } function Script(props, context) { const { __scripts = [] } = context; + const consumer = getConsumer(props); + + if (typeof consumer === 'function') { + return consumer(__scripts); + } // props such as type can be passed to script tag // script default crossorigin value is anonymous @@ -72,7 +82,7 @@ function App(props, context) { return route.path == pagePath; }); - const consumer = Array.isArray(props.children) ? props.children[0] : props.children; + const consumer = getConsumer(props); if (typeof consumer === 'function') { return consumer(currentPageInfo); @@ -81,6 +91,10 @@ function App(props, context) { return props.children; } +function getConsumer(props) { + return Array.isArray(props.children) ? props.children[0] : props.children +} + export { Root, Data, From b88dfe04b48c1ab47ae9e9bbbce933e9da5d4e80 Mon Sep 17 00:00:00 2001 From: MO <9125255+fengzilong@users.noreply.github.com> Date: Sat, 9 Oct 2021 19:06:38 +0800 Subject: [PATCH 2/2] chore: bump version and update changelog --- packages/rax-document/CHANGELOG.md | 4 ++++ packages/rax-document/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/rax-document/CHANGELOG.md b/packages/rax-document/CHANGELOG.md index 16e22ed27..f385d2e80 100644 --- a/packages/rax-document/CHANGELOG.md +++ b/packages/rax-document/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.1.7 + +- Feature: support customize styles and scripts + ## v0.1.6 - Chore: bundle script should add `crossorigin="anonymous"` default diff --git a/packages/rax-document/package.json b/packages/rax-document/package.json index dcf3e033b..d89bb375a 100644 --- a/packages/rax-document/package.json +++ b/packages/rax-document/package.json @@ -1,6 +1,6 @@ { "name": "rax-document", - "version": "0.1.6", + "version": "0.1.7", "description": "Provide components for building Document", "license": "BSD-3-Clause", "main": "lib/index.js",