Skip to content

Redundant re-implementations #186

@KaelWD

Description

@KaelWD

createSingle wraps createSelection and adds singular getters but also duplicates unselect and toggle functions that just call the original:

function unselect (id: ID) {
registry.unselect(id)
}
function toggle (id: ID) {
if (registry.selectedIds.has(id)) unselect(id)
else registry.select(id)
}
function toggle (id: ID) {
if (toValue(model.disabled)) return
if (model.selectedIds.has(id)) unselect(id)
else select(id)
}

createSelection wraps createModel adding mandatory, most of its functions are direct copies:

function select (id: ID) {
if (toValue(model.disabled)) return
const item = model.get(id)
if (!item || toValue(item.disabled)) return
if (!toValue(multiple)) model.selectedIds.clear()
model.selectedIds.add(id)
}
function select (id: ID) {
if (toValue(disabled)) return
const item = registry.get(id)
if (!item || toValue(item.disabled)) return
if (!toValue(multiple)) selectedIds.clear()
selectedIds.add(id)
}
function toggle (id: ID) {
if (toValue(model.disabled)) return
if (model.selectedIds.has(id)) unselect(id)
else select(id)
}
function toggle (id: ID) {
if (toValue(disabled)) return
if (selected(id)) unselect(id)
else select(id)
}

createModel apparently supports multiple but has another copy of apply that ignores the multiple option and only uses the first value. createSelection also re-uses the tsdoc description that says "for API compatibility with createSelection. The multiple field is accepted but ignored".

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions