Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 46x 46x 46x 12x 12x 12x 12x 12x 12x 12x 12x 46x 46x 46x 12x | import { ProxyHandlerFactory } from './proxyHandler.js';
/**
* Factory for creating reactive state objects.
*/
export class StateFactory {
/**
* @param {typeof ProxyHandlerFactory} [handlerFactoryClass=ProxyHandlerFactory] - The factory class to create proxy handlers.
*/
constructor(handlerFactoryClass = ProxyHandlerFactory) {
/** @type {typeof ProxyHandlerFactory} */
this.handlerFactoryClass = handlerFactoryClass;
}
/**
* Creates a reactive proxy for the given initial state.
* @param {Object} [initialState={}] - The initial state object.
* @param {Object} [options={}] - Configuration options for the proxy handler.
* @returns {Proxy} The reactive state proxy.
*/
create(initialState = {}, options = {}) {
const handlerFactory = new this.handlerFactoryClass(options);
return new Proxy(initialState, handlerFactory.create());
}
}
|