From 105944129039d54529bed836aaca8490f4866e69 Mon Sep 17 00:00:00 2001 From: ShanaMaid Date: Fri, 15 Feb 2019 14:19:53 +0800 Subject: [PATCH] feat: Icon support svgCache --- CHANGELOG.md | 27 +++++++++++++++++++++++++++ components/Icon/Icon.tsx | 16 ++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf2356f..9c771ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,30 @@ +## [0.8.18](https://github.com/Yoshino-UI/Yoshino/compare/v0.8.17...v0.8.18) (2019-01-29) + + +### Features + +* **icon:** support archer-svgs ([4ea2818](https://github.com/Yoshino-UI/Yoshino/commit/4ea2818)) + + + +## [0.8.17](https://github.com/Yoshino-UI/Yoshino/compare/v0.8.16...v0.8.17) (2019-01-28) + + +### Features + +* **select:** add `checkmark` for choosed opt ([fa8185c](https://github.com/Yoshino-UI/Yoshino/commit/fa8185c)) + + + +## [0.8.16](https://github.com/Yoshino-UI/Yoshino/compare/v0.8.15...v0.8.16) (2019-01-23) + + +### Bug Fixes + +* **input:** value -> string ([ef60641](https://github.com/Yoshino-UI/Yoshino/commit/ef60641)) + + + ## [0.8.15](https://github.com/Yoshino-UI/Yoshino/compare/v0.8.14...v0.8.15) (2019-01-23) diff --git a/components/Icon/Icon.tsx b/components/Icon/Icon.tsx index c87ef5a..a918643 100644 --- a/components/Icon/Icon.tsx +++ b/components/Icon/Icon.tsx @@ -21,6 +21,8 @@ export interface IIconState { } const svgTarget = 'https://unpkg.com/ionicons@4.4.2/dist/ionicons/svg/'; +const svgCaches: {[index: string]: string} = {}; + /** * **图标**-展示对应的矢量化图标。 */ @@ -29,6 +31,16 @@ export class Icon extends Component { svgHtml: '' }; + getSvg = async (type: string) => { + let svg: string; + if (type in svgCaches) { + svg = svgCaches[type]; + } else { + svg = await Archer.fetchSvg(`${svgTarget}${type}.svg`); + } + return svg; + } + async componentDidMount() { // 不使用ionicons图标时不进行加载,提高性能 if (!this.props.type) { @@ -36,7 +48,7 @@ export class Icon extends Component { } // tslint:disable-next-line no-any - const svg = await Archer.fetchSvg(`${svgTarget}${this.props.type}.svg`); + const svg = await this.getSvg(this.props.type); this.setState({ svgHtml: svg, }); @@ -49,7 +61,7 @@ export class Icon extends Component { if (this.props.type !== props.type) { // tslint:disable-next-line no-any - const svg = await Archer.fetchSvg(`${svgTarget}${props.type}.svg`); + const svg = await this.getSvg(props.type); this.setState({ svgHtml: svg, });