or.js (710B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* global ConditionBase */ 6 7 /** 8 * OR condition 9 */ 10 class ConditionOr extends ConditionBase { 11 #conditions; 12 13 constructor(factory, desc) { 14 super(factory, desc); 15 16 this.#conditions = desc.conditions.map(c => factory.create(c)); 17 } 18 19 async init() { 20 for (const c of this.#conditions) { 21 await c.init(); 22 } 23 } 24 25 check() { 26 for (const c of this.#conditions) { 27 if (c.check()) { 28 return true; 29 } 30 } 31 return false; 32 } 33 } 34 35 globalThis.ConditionOr = ConditionOr;