faster classname function

This commit is contained in:
Nolan Lawson 2018-03-14 18:52:33 -07:00
parent 2db30856f9
commit 1477fbfbda
3 changed files with 23 additions and 4 deletions

View File

@ -60,16 +60,19 @@
} }
</style> </style>
<script> <script>
import { classname } from '../_utils/classname'
export default { export default {
computed: { computed: {
computedClass: (pressable, pressed, big, className) => { computedClass: (pressable, pressed, big, className) => {
return [ return classname(
'icon-button', 'icon-button',
!pressable && 'not-pressable', !pressable && 'not-pressable',
pressed && 'pressed', pressed && 'pressed',
big && 'big-icon', big && 'big-icon',
className className
].filter(Boolean).join(' ') )
} }
} }
} }

View File

@ -94,6 +94,7 @@
import { store } from '../../_store/store' import { store } from '../../_store/store'
import { goto } from 'sapper/runtime.js' import { goto } from 'sapper/runtime.js'
import { registerClickDelegate, unregisterClickDelegate } from '../../_utils/delegate' import { registerClickDelegate, unregisterClickDelegate } from '../../_utils/delegate'
import { classname } from '../../_utils/classname'
export default { export default {
oncreate() { oncreate() {
@ -124,11 +125,11 @@
store: () => store, store: () => store,
helpers: { helpers: {
getClasses(originalStatus, timelineType, isStatusInOwnThread) { getClasses(originalStatus, timelineType, isStatusInOwnThread) {
return [ return classname(
originalStatus.visibility === 'direct' && 'status-direct', originalStatus.visibility === 'direct' && 'status-direct',
timelineType !== 'search' && 'status-in-timeline', timelineType !== 'search' && 'status-in-timeline',
isStatusInOwnThread && 'status-in-own-thread' isStatusInOwnThread && 'status-in-own-thread'
].filter(Boolean).join(' ') )
} }
}, },
methods: { methods: {

View File

@ -0,0 +1,15 @@
export function classname () {
let res = ''
let len = arguments.length
let i = -1
while (++i < len) {
let item = arguments[i]
if (item) {
if (res) {
res += ' '
}
res += item
}
}
return res
}