MCPcopy Create free account
hub / github.com/activejs/activejs / constructor

Function constructor

packages/core/src/lib/abstract-base.ts:117–154  ·  view source on GitHub ↗
(config?: BaseConfig)

Source from the content-addressed store, hash-verified

115 // tslint:enable:variable-name
116
117 protected constructor(config?: BaseConfig) {
118 super();
119
120 this.config = {...config};
121
122 if (this.config.id !== undefined) {
123 if (!isValidId(this.config.id)) {
124 throw new TypeError(
125 `Invalid id provided, expected a non-empty string, got ${String(this.config.id)}`
126 );
127 }
128 if (Configuration.ENVIRONMENT.checkUniqueId === true) {
129 const locationId = getLocationId(this);
130 if (
131 UniqueIdsAndLocationIdMap[this.config.id] != null &&
132 UniqueIdsAndLocationIdMap[this.config.id] !== locationId
133 ) {
134 throw new TypeError(
135 `Duplicate id "${this.config.id}" detected by "checkUniqueId" check, consider assigning a unique id.`
136 );
137 }
138 UniqueIdsAndLocationIdMap[this.config.id] = locationId;
139 }
140 } else if ((this.config as UnitConfig<any>).persistent === true) {
141 throw new TypeError(`An id is required for persistence to work.`);
142 }
143
144 if (this.config.replay === false) {
145 this.sourceSubject = this.futureSubject;
146 (this as any).source = this.future$;
147 } else {
148 this.sourceSubject = new BehaviorSubject(undefined);
149 (this as any).source = this.sourceSubject.asObservable();
150 }
151
152 this.setupEvents();
153 Object.freeze(this.config);
154 }
155
156 /**
157 * Creates a new Observable using the default Observable as source.

Callers

nothing calls this directly

Calls 3

isValidIdFunction · 0.90
getLocationIdFunction · 0.90
asObservableMethod · 0.80

Tested by

no test coverage detected