Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const self = this
const entry = d.entry(args)
// cache hit, return
if (entry.exists()) return entry.get().get()
// if function is invoked, and its a cache miss without reactive, there is no point in caching...
if (!opts.keepAlive && !_isComputingDerivation()) {
if (!memoWarned) {
console.warn(
"invoking a computedFn from outside an reactive context won't be memoized, unless keepAlive is set"
)
memoWarned = true
}
return fn.apply(self, args)
}
// create new entry
const c = computed(
() => {
return fn.apply(self, args)
},
{
...opts,
name: `computedFn(${fn.name}#${++i})`
}
)
entry.set(c)
// clean up if no longer observed
if (!opts.keepAlive)
onBecomeUnobserved(c, () => {
d.entry(args).delete()
})
// return current val
return c.get()
eps(subjectId) {
return computed(() => {
const eps = subjectStore.subjectEp(subjectId).eps || []
const { length } = eps
// 集数超过了1页的显示个数
if (length > Eps.pageLimit) {
const userProgress = this.userProgress(subjectId)
const index = eps.findIndex(
item => item.type === 0 && userProgress[item.id] !== '看过'
)
// 找不到未看集数, 返回最后的数据
if (index === -1) {
return eps.slice(length - Eps.pageLimit - 1, length - 1)
}
// 找到第1个未看过的集数, 返回1个看过的集数和剩余的集数
type(page) {
return computed(() => {
const { title } = tabs[page]
if (title === '小组') {
const { group } = this.state
const label = MODEL_RAKUEN_TYPE_GROUP.getLabel(group)
return MODEL_RAKUEN_TYPE_GROUP.getValue(label)
}
if (title === '人物') {
const { mono } = this.state
const label = MODEL_RAKUEN_TYPE_MONO.getLabel(mono)
return MODEL_RAKUEN_TYPE_MONO.getValue(label)
}
return MODEL_RAKUEN_TYPE.getValue(title)
}).get()
}
tag(text = '', type = DEFAULT_TYPE, airtime = '') {
const _text = text.replace(/ /g, '+')
return computed(
() => this.state.tag[`${_text}|${type}|${airtime}`] || LIST_EMPTY
).get()
}
temple(hash = this.hash) {
return computed(() => this.state.temple[hash]).get() || LIST_EMPTY
}
list(key = 'bid') {
return computed(() => tinygrailStore.list(key)).get()
}
usersInfo(id) {
return computed(() => userStore.usersInfo(id)).get()
}
const disposableComputedExpr = (fn: () => T): IComputedValue => {
let latest: T | undefined
const expr = computed(() => {
latest && latest.dispose()
latest = fn()
return latest
})
onBecomeUnobserved(expr, () => latest && latest.dispose())
return expr
}
isFavor(topicId) {
return computed(() => rakuenStore.favor(topicId)).get()
}
getItem(key) {
return computed(() => this._data.get(key)).get();
}