MCPcopy Index your code
hub / github.com/Tencent/kbone / toggle

Function toggle

packages/miniprogram-render/src/node/class-list.js:150–168  ·  view source on GitHub ↗
(className, force)

Source from the content-addressed store, hash-verified

148 },
149
150 toggle(className, force) {
151 if (typeof className !== 'string') return false
152
153 className = className.trim()
154
155 if (!className) return false
156
157 const isNotContain = this.indexOf(className) === -1
158 let action = isNotContain ? 'add' : 'remove'
159 action = force === true ? 'add' : force === false ? 'remove' : action
160
161 if (action === 'add') {
162 this.add(className)
163 } else {
164 this.remove(className)
165 }
166
167 return force === true || force === false ? force : isNotContain
168 },
169
170 toString() {
171 return this.join(' ')

Callers

nothing calls this directly

Calls 2

addMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected