Uber μμ λ§λ react-vis λ₯Ό ꡬ경νλ€κ° μ€κ°μ if()μμ λ€μ Boolean() ν¨μλ₯Ό μ¨μ if(Boolean())μΌλ‘ κ°μ κ²μ¬νλ λΆλΆμ΄ μμλ€ λ§ν¬
export function applyTransition(props, elements) {
let { animation } = props
if (Boolean(animation)) {
if (!(animation instanceof Object)) {
animation = DEFAULT_ANIMATION
}
return elements.transition().duration(animation.duration)
}
return elements
}
νΉμ Boolean()μ΄ λμμ΄ λ€λ₯ΌκΉν΄μ μ΄κ²μ κ² λΉκ΅ν΄λ³΄λ μ½λλ₯Ό μ§λ³΄μμΌλ
var values = {
_true: true,
_false: false,
_string: 'hello',
_stringEmpty: '',
_number: 1,
_numberZero: 0,
_null: null,
_emptyObject: {},
_filledObject: { a: 1 },
_emptyArray: [],
_filledArray: [1],
}
var valueNames = Object.getOwnPropertyNames(values)
valueNames.forEach(function(valueName, idx) {
var value = values[valueName]
if (Boolean(value) == true) console.log(valueName + ' true in Boolean()')
else console.log(valueName + ' false in Boolean()')
if (value) console.log(valueName + ' true in if()')
else console.log(valueName + ' false in if()')
})
λ±ν evaluation μ΄ λ€λ₯΄μ§λ μλ€.
μ¬μ§μ΄ κ·Έ λ°μ λ€λ₯Έ ν¨μμμλ κ·Έλ₯ if()λ₯Ό μ΄λ€. λ±ν μ©λκ° λ€λ₯Έ κ² κ°μ§λ μμλ°β¦
export function getCSSAnimation(props, style) {
let { animation } = props
let transition = 'none'
if (animation) {
// Fallback to default animation if no animation is passed.
if (!(animation instanceof Object)) {
animation = DEFAULT_ANIMATION
}
const keys = Object.keys(style)
// Create a string of visualized parameters and filter out those, which
// don't have values.
const animationKeys = keys
.filter(key => Boolean(style[key]))
.map(key => `${key} ${animation.duration / 1000}s`)
if (animationKeys.length) {
transition = animationKeys.join(',')
}
}
return {
transition,
...style,
}
}
μ μ¬λλ€μ΄ μ½λ리뷰λ₯Ό μ νμ리λ μκ³ , μμμμ μ§μ§ λͺ¨λ₯΄κ² λ€γ γ γ .