MCPcopy Create free account
hub / github.com/json-editor/json-editor / checkDependency

Method checkDependency

src/editor.js:171–210  ·  view source on GitHub ↗
(path, choices)

Source from the content-addressed store, hash-verified

169 }
170
171 checkDependency (path, choices) {
172 if (this.path === path || this.jsoneditor === null) {
173 return
174 }
175
176 const editor = this.jsoneditor.getEditor(path)
177 const value = editor ? editor.getValue() : undefined
178
179 if (!editor || !editor.dependenciesFulfilled || value === undefined || value === null) {
180 this.dependenciesFulfilled = false
181 } else if (Array.isArray(choices)) {
182 this.dependenciesFulfilled = choices.some(choice => {
183 if (JSON.stringify(value) === JSON.stringify(choice)) {
184 return true
185 }
186 })
187 } else if (typeof choices === 'object') {
188 if (typeof value !== 'object') {
189 this.dependenciesFulfilled = choices === value
190 } else {
191 Object.keys(choices).some(key => {
192 if (!hasOwnProperty(choices, key)) {
193 return false
194 }
195 if (!hasOwnProperty(value, key) || choices[key] !== value[key]) {
196 this.dependenciesFulfilled = false
197 return true
198 }
199 })
200 }
201 } else if (typeof choices === 'string' || typeof choices === 'number') {
202 this.dependenciesFulfilled = this.dependenciesFulfilled && value === choices
203 } else if (typeof choices === 'boolean') {
204 if (choices) {
205 this.dependenciesFulfilled = this.dependenciesFulfilled && (value || value.length > 0)
206 } else {
207 this.dependenciesFulfilled = this.dependenciesFulfilled && (!value || value.length === 0)
208 }
209 }
210 }
211
212 setContainer (container) {
213 this.container = container

Callers 1

evaluateDependenciesMethod · 0.95

Calls 3

hasOwnPropertyFunction · 0.90
getEditorMethod · 0.80
getValueMethod · 0.45

Tested by

no test coverage detected