Skip to content

Commit

Permalink
feat: Icon support svgCache
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaMaid committed Feb 15, 2019
1 parent 99fe865 commit 1059441
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
16 changes: 14 additions & 2 deletions components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface IIconState {
}

const svgTarget = 'https://unpkg.com/ionicons@4.4.2/dist/ionicons/svg/';
const svgCaches: {[index: string]: string} = {};

/**
* **图标**-展示对应的矢量化图标。
*/
Expand All @@ -29,14 +31,24 @@ export class Icon extends Component<IIconProps, IIconState> {
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) {
return;
}

// 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,
});
Expand All @@ -49,7 +61,7 @@ export class Icon extends Component<IIconProps, IIconState> {

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,
});
Expand Down

0 comments on commit 1059441

Please sign in to comment.