

export class RemoteStateDefiner {

	#scope
	#to_observe

	constructor(scope, to_observe) {
		this.#to_observe = to_observe
		this.#scope = scope
	}

	observe(key, tags_or_json, json_or_key_generator) {
		const address_str = JSON.stringify(this.#scope.concat([key].flat())).slice(1,-1)
		if (typeof json_or_key_generator === 'function') {
			// wildcard observe
			this.#to_observe[address_str] = { tag: tags_or_json, key: json_or_key_generator }
		} else {
			// object observe
			if (!Array.isArray(tags_or_json))  throw new "observe method needs either (address, tags_array, json) or (address, tag)"
			this.#to_observe[address_str] = { tags: tags_or_json, json: json_or_key_generator }
		}
	}

}
