* Validates the value. If it fails, it calls the function in the second * Argument. Pass null to remove existing value.
(newVal: JSONValue)
| 276 | * Argument. Pass null to remove existing value. |
| 277 | */ |
| 278 | async function validateAndSet(newVal: JSONValue): Promise<void> { |
| 279 | if (newVal == null) { |
| 280 | // remove the value |
| 281 | resource.removePropVal(propertyURL); |
| 282 | set(null); |
| 283 | return; |
| 284 | } |
| 285 | set(newVal); |
| 286 | setTouched(true); |
| 287 | |
| 288 | /** |
| 289 | * Validates and sets a property / value combination. Will invoke the |
| 290 | * callback if the value is not valid. |
| 291 | */ |
| 292 | async function setAsync() { |
| 293 | try { |
| 294 | await resource.set(propertyURL, newVal, store, validate); |
| 295 | handleValidationError && handleValidationError(null); |
| 296 | // commit && (await resource.save(store)); |
| 297 | store.notify(resource); |
| 298 | } catch (e) { |
| 299 | handleValidationError ? handleValidationError(e) : console.log(e); |
| 300 | } |
| 301 | } |
| 302 | await setAsync(); |
| 303 | } |
| 304 | |
| 305 | // If a value has already been set, return it. |
| 306 | if (val !== null) { |
nothing calls this directly
no test coverage detected