UNPKG

@etsoo/react

Version:

TypeScript ReactJs UI Independent Framework

43 lines (42 loc) 1.21 kB
import { State } from "./State"; // Calls const calls = { /** * Key value * @param key Item key */ get(key) { const resources = this.state.resources; const value = typeof resources === "object" ? resources[key] : undefined; if (value == null) return undefined; return value; } }; /** * Culture state * Creator for culture context and provider globally, not inside a component to avoid problem: * Cannot update a component (`provider`) while rendering a different component */ export class CultureState { /** * Constructor */ constructor(item) { // Default const defaultItem = item ?? {}; // Load resources if (item != null && typeof item.resources !== "object") item.resources().then((result) => (item.resources = result)); // Act const { context, provider } = State.create((state, action) => { // Language reducer if (state.name !== action.name) { return { ...action }; } return state; }, defaultItem, calls); this.context = context; this.provider = provider; } }