Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
Removed type property
Browse files Browse the repository at this point in the history
Creation was not possible and we can achieve the same thing with
"crit" in props. See also microsoft/TypeScript#12052
  • Loading branch information
eps1lon committed Feb 27, 2018
1 parent bb306a7 commit c0d8219
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Popup, Rarity, ItemType } from './item';
export { Popup, Rarity } from './item';
export { Group as ModGroup, Type as ModType } from './mod';
2 changes: 1 addition & 1 deletion src/item/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as Popup } from './popup';
export { Rarity, Type as ItemType } from './poe';
export { Rarity} from './poe';
15 changes: 3 additions & 12 deletions src/item/poe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { SingleValue, Value, AugmentableValue } from '../util/value';

// use intersection here instead of extends to be able to test Properties
// with only e.g. ArmourProperties
export type Item = AbstractItem &
(ArmourProperties | WeaponProperties | NoProperties);
export type Item = AbstractItem & Properties;

export interface AbstractItem {
base: BaseItem;
Expand All @@ -24,18 +23,13 @@ export interface AbstractItem {
shaper?: boolean;
}

export enum Type {
none,
armour,
weapon,
}
export type Properties = ShieldProperties | ArmourProperties | WeaponProperties | NoProperties;

export interface AbstractProperties {
quality?: number;
}

export interface ArmourProperties extends AbstractProperties {
type: Type.armour;
armour?: AugmentableValue<SingleValue>;
energy_shield?: AugmentableValue<SingleValue>;
evasion?: AugmentableValue<SingleValue>;
Expand All @@ -47,7 +41,6 @@ export interface ShieldProperties extends ArmourProperties {
}

export interface WeaponProperties extends AbstractProperties {
type: Type.weapon;
physical_damage?: AugmentableValue;
cold_damage?: Value;
fire_damage?: Value;
Expand All @@ -66,9 +59,7 @@ export interface WeaponProperties extends AbstractProperties {
crit?: AugmentableValue<SingleValue>;
}

export interface NoProperties extends AbstractProperties {
type?: Type.none;
}
export interface NoProperties extends AbstractProperties {}

export interface BaseItem {
name: string;
Expand Down
39 changes: 9 additions & 30 deletions src/item/popup/body/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ArmourProperties,
NoProperties,
ShieldProperties,
Type,
} from '../../poe';
import { round, msToPerSecond, asPercentString } from '../../../util/number';
import {
Expand All @@ -30,26 +29,18 @@ export default class Properties extends React.PureComponent<Props> {
return true;
}

switch (properties.type) {
case Type.armour:
const { armour, energy_shield, evasion } = properties;
if ("armour" in properties) {
const { armour, energy_shield, evasion } = properties;
return (
augmentableNotZero(armour) ||
augmentableNotZero(energy_shield) ||
augmentableNotZero(evasion)
);
case Type.weapon:
} else if ("aps" in properties) {
// at least display weapon type
return true;
case Type.none:
case undefined:
return false;
default:
// while the exhaustiveness check is nice for internal use
// it's not guarenteed at runtime since this component can be consumed
// by normal js
// @ts-ignore
throw new Error(`unrecognized property kind '${properties.kind}'`);
} else {
return false;
}
}

Expand All @@ -73,22 +64,10 @@ export default class Properties extends React.PureComponent<Props> {
);
}

switch (properties.type) {
case Type.armour:
display_properties.push(...this.armourProperties(properties));
break;
case Type.weapon:
display_properties.push(...this.weaponProperties(properties));
break;
case Type.none:
case undefined:
break;
default:
// while the exhaustiveness check is nice for internal use
// it's not guarenteed at runtime since this component can be consumed
// by normal js
// @ts-ignore
throw new Error(`unrecognized property kind '${properties.kind}'`);
if ("armour" in properties) {
display_properties.push(...this.armourProperties(properties));
} else if ("aps" in properties) {
display_properties.push(...this.weaponProperties(properties));
}

return display_properties;
Expand Down
3 changes: 1 addition & 2 deletions stories/docs/helmet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { storiesOf } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';
import { formatStats } from 'poe-i18n';
// 'poe-components-item'
import { Popup, Rarity, ModType, ItemType } from '../../src/';
import { Popup, Rarity, ModType } from '../../src/';

import '../../themes/poe.scss';

Expand All @@ -22,7 +22,6 @@ storiesOf('ItemPopup', module).add(
name: 'Hubris Circlet',
},
name: 'Mind Brow',
type: ItemType.armour,
rarity: Rarity.rare,
energy_shield: {
value: 200,
Expand Down
3 changes: 1 addition & 2 deletions stories/docs/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { formatStats, Fallback } from 'poe-i18n';
// 'poe-components-item'
import { Popup, Rarity, ModType, ItemType } from '../../src/';
import { Popup, Rarity, ModType } from '../../src/';

const base_item_types = require('poe-i18n/locale-data/en/BaseItemTypes.json');
const stat_descriptions = require('poe-i18n/locale-data/en/stat_descriptions.json');
Expand Down Expand Up @@ -39,7 +39,6 @@ storiesOf('i18n integration', module).add('Helmet', () => (
name: base_item_types['1768'].name,
},
name: 'Mind Brow',
type: ItemType.armour,
rarity: Rarity.rare,
energy_shield: {
value: 200,
Expand Down

0 comments on commit c0d8219

Please sign in to comment.