(cell: dia.Cell, changed: any, opt: dia.Cell.Options = {})
| 52 | |
| 53 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 54 | function __updateBindings(cell: dia.Cell, changed: any, opt: dia.Cell.Options = {}) { |
| 55 | const attrs = {}; |
| 56 | |
| 57 | const changedBindings = bindings.filter(binding => binding.triggers.some(trigger => Object.keys(changed).includes(trigger))); |
| 58 | |
| 59 | for (const { id, path, expression, args, isFunction, triggers, name } of changedBindings) { |
| 60 | const existingExpression = util.getByPath(attrs, path); |
| 61 | let evalExpression; |
| 62 | |
| 63 | if (existingExpression !== undefined) { |
| 64 | // one of the bound properties has been already resolved |
| 65 | evalExpression = existingExpression; |
| 66 | } else { |
| 67 | evalExpression = expression; |
| 68 | } |
| 69 | const expressionRegex = new RegExp(`\\${id}`, 'g'); |
| 70 | let value = cell.attributes[triggers[0]]; |
| 71 | |
| 72 | if (isFunction) { |
| 73 | const attributeValues = triggers.map(attribute => cell.attributes[attribute]); |
| 74 | // @ts-expect-error - functions is not typed |
| 75 | const functions = cell.constructor['functions'] || {}; |
| 76 | if (name in functions) { |
| 77 | value = functions[name].call(cell, ...attributeValues, ...args); |
| 78 | } else { |
| 79 | throw new Error(`Function '${name}' is not defined.`); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | evalExpression = evalExpression.replace(expressionRegex, value); |
| 84 | util.setByPath(attrs, path, evalExpression); |
| 85 | } |
| 86 | |
| 87 | opt.unset = false; |
| 88 | cell.attr(attrs, opt); |
| 89 | } |
| 90 | |
| 91 | function __onChange(this: dia.Cell, cell: dia.Cell, opt: dia.Cell.Options = {}) { |
| 92 | __updateBindings(cell, this.changed, opt); |
no test coverage detected