From 7228a74a971d30b2791184d1d8c2be0bb96f3375 Mon Sep 17 00:00:00 2001 From: Nick Olszanski Date: Sat, 8 Oct 2022 16:32:11 +0200 Subject: [PATCH] Update issue templates (#31) * rename: makeRoot -> createContainer * fix spelling * update readme * Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 14 +++++++ .github/ISSUE_TEMPLATE/feature_request.md | 19 +++++++++ examples/cra/src/containers/_root.store.ts | 4 +- examples/node-cli/src/server.ts | 14 +++---- examples/vite-app/src/_bl.ts | 4 +- iti-react/notes-and-ideas.md | 2 +- iti-react/src/index.ts | 2 +- iti-react/tests/mocks/_mock-app-container.ts | 4 +- iti/README.md | 41 +++++++++---------- iti/notes-and-ideas.md | 2 +- iti/src/index.ts | 2 +- iti/src/iti.ts | 2 +- iti/tests/container-get-values.spec.ts | 6 +-- iti/tests/dispose-graph.ts.api.spec.ts | 4 +- iti/tests/dispose.ts.api.spec.ts | 16 ++++---- iti/tests/exotic.spec.ts | 6 +-- iti/tests/getter.spec.ts | 28 ++++++------- iti/tests/mocks/_mock-app-container.ts | 4 +- iti/tests/tsd.getter.tsd-only.ts | 4 +- iti/tests/update.api.spec.ts | 6 +-- website/docs/1.intro.md | 2 +- website/docs/4.usage.md | 8 ++-- website/docs/5.patterns-and-tips.md | 16 ++++---- website/docs/6.getting-started.md.del | 4 +- .../docs/6_async_start-PART-2/main-example.ts | 4 +- website/docs/6_async_start-PART-2/main/app.ts | 4 +- website/docs/9.api.md | 6 +-- website/docs/async-di/5.iti.mdx | 4 +- website/docs/basic-di/5.iti.mdx | 4 +- website/docs/basic-di/6.iti-vs-pure.mdx | 2 +- website/docs/examples/circular-dependency.ts | 4 +- website/docs/with-react/configuration.md | 4 +- 32 files changed, 139 insertions(+), 107 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..fe2b692 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,14 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +Can you reproduce it on an external resource, like Stackblitz? +https://stackblitz.com/github/molszanski/iti-playground/tree/main?file=src%2F_0.business-logic.ts&file=src%2FApp.tsx diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..08d0d64 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,19 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**What would be an ideal API for your use case?** + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/examples/cra/src/containers/_root.store.ts b/examples/cra/src/containers/_root.store.ts index 9c5a69c..cf13e6c 100644 --- a/examples/cra/src/containers/_root.store.ts +++ b/examples/cra/src/containers/_root.store.ts @@ -1,4 +1,4 @@ -import { makeRoot } from "iti" +import { createContainer } from "iti" import { provideAContainer } from "./container.a" import { provideAuthContainer } from "./container.auth" @@ -12,7 +12,7 @@ import { provideFatLib2 } from "./container.fat-lib2" export type PizzaAppCoreContainer = ReturnType export function pizzaAppCore() { - return makeRoot() + return createContainer() .add(() => ({ auth: async () => provideAuthContainer(), })) diff --git a/examples/node-cli/src/server.ts b/examples/node-cli/src/server.ts index 648fa88..ed7d47d 100644 --- a/examples/node-cli/src/server.ts +++ b/examples/node-cli/src/server.ts @@ -1,5 +1,5 @@ import _ from "lodash" -import { makeRoot } from "iti" +import { createContainer } from "iti" // Step 1: Your application logic stays clean class Oven { @@ -13,13 +13,13 @@ class Kitchen { } // Step 2: Add and read simple tokens -let root = makeRoot().add({ +let root = createContainer().add({ userManual: "Please preheat before use", oven: () => new Oven(), }) root.get("oven") -// Step 3: Add a usefull async provider / container +// Step 3: Add a useful async provider / container const kitchenContainer = async ({ oven, userManual }) => { await oven.preheat() return { @@ -52,16 +52,16 @@ await root.getContainerSet(["oven", "userManual"]) // { userManual: '...', oven: await root.getContainerSet((c) => [c.userManual, c.oven]) // same as above // Subscribe to container changes -node.subscribeToContiner("oven", (oven) => {}) -node.subscribeToContinerSet(["oven", "kitchen"], ({ oven, kitchen }) => {}) +node.subscribeToContainer("oven", (oven) => {}) +node.subscribeToContainerSet(["oven", "kitchen"], ({ oven, kitchen }) => {}) // prettier-ignore -node.subscribeToContinerSet((c) => [c.kitchen], ({ oven, kitchen }) => {}) +node.subscribeToContainerSet((c) => [c.kitchen], ({ oven, kitchen }) => {}) node.on("containerUpdated", ({ key, newContainer }) => {}) node.on("containerUpserted", ({ key, newContainer }) => {}) // ----Adding -let node1 = makeRoot() +let node1 = createContainer() .add({ userManual: "Please preheat before use", oven: () => new Oven(), diff --git a/examples/vite-app/src/_bl.ts b/examples/vite-app/src/_bl.ts index 130af3d..f816f63 100644 --- a/examples/vite-app/src/_bl.ts +++ b/examples/vite-app/src/_bl.ts @@ -1,4 +1,4 @@ -import { makeRoot } from "iti" +import { createContainer } from "iti" export class A {} export class B { @@ -8,7 +8,7 @@ export class C { constructor(a: A, b: B) {} } -export const app = makeRoot() +export const app = createContainer() .add(() => ({ a: () => new A(), })) diff --git a/iti-react/notes-and-ideas.md b/iti-react/notes-and-ideas.md index d454fdb..11df3f8 100644 --- a/iti-react/notes-and-ideas.md +++ b/iti-react/notes-and-ideas.md @@ -3,7 +3,7 @@ For runtime optimizations of the search in async nodes we can provide tokens as a second argument in an `addPromise ` ```ts -let n = makeRoot() +let n = createContainer() .addNode({ a: 1, b: 2 }) .addPromise( async (c) => { diff --git a/iti-react/src/index.ts b/iti-react/src/index.ts index c427754..e22fce5 100644 --- a/iti-react/src/index.ts +++ b/iti-react/src/index.ts @@ -1,4 +1,4 @@ -// export { makeRoot, RootContainer } from "./library.root-container" +// export { createContainer, RootContainer } from "./library.root-container" export type { GetContainerFormat, UnPromisify } from "./_utils" // React diff --git a/iti-react/tests/mocks/_mock-app-container.ts b/iti-react/tests/mocks/_mock-app-container.ts index 3ff9dd3..885b496 100644 --- a/iti-react/tests/mocks/_mock-app-container.ts +++ b/iti-react/tests/mocks/_mock-app-container.ts @@ -1,4 +1,4 @@ -import { makeRoot } from "iti" +import { createContainer } from "iti" import { provideAContainer } from "./container.a" import { provideBContainer } from "./container.b" @@ -6,7 +6,7 @@ import { provideCContainer } from "./container.c" export type MockAppNode = ReturnType export function getMainMockAppContainer() { - let node = makeRoot() + let node = createContainer() let k = node .upsert({ aCont: async () => provideAContainer() }) .upsert((c) => { diff --git a/iti/README.md b/iti/README.md index b92295c..3990803 100644 --- a/iti/README.md +++ b/iti/README.md @@ -8,12 +8,14 @@ # Iti -

1kB Dependency Injection Library for Typescript and React with a unique support of async flow

+

~1kB Dependency Injection Library for Typescript and React with a unique async flow support

CI Status npm version gzip + + Coverage Mutation Score

@@ -330,35 +332,32 @@ Plainly removes token and value from an instance ### `dispose` -Related toa a conversation with @moltar -https://github.com/molszanski/iti/issues/21 +Please check a full [documentation](https://itijs.org/docs/api#disposing) on disposing. + +Short version: ```ts class DatabaseConnection { - disconnect(): Promise { - // ... disconnect - } + connect(): Promise {} + disconnect(): Promise {} } - -let node = createContainer() - .add({ - db: () => new DatabaseConnection(), - }) +const container = createContainer() + .add(() => ({ + dbConnection: async () => { + const db = new DatabaseConnection() + await db.connect() + return db + }, + })) .addDisposer({ - // Note that for convenience we provide an instance of the cached value as an argument - db: (db) => db.disconnect(), + // ↓ `db` is a resolved value of a `dbConnection` token. Pretty handy + dbConnection: (db) => db.disconnect(), }) -// We can dispose nodes individually -await node.dispose("db") - -// dispose all resources -await node.disposeAll() +const db = await container.get("dbConnection") +await container.disposeAll() ``` -please note that `.dispose('token')` doesn't dispose child elements. This would be risky to implement due to reasons explained in -[dispose-graph.ts.api.spec.ts](./iti/tests/dispose-graph.ts.api.spec.ts.) - # Alternatives ## No async support diff --git a/iti/notes-and-ideas.md b/iti/notes-and-ideas.md index 6c9ec10..86a34ef 100644 --- a/iti/notes-and-ideas.md +++ b/iti/notes-and-ideas.md @@ -3,7 +3,7 @@ For runtime optimizations of the search in async nodes we can provide tokens as a second argument in an `addPromise ` ```ts -let n = makeRoot() +let n = createContainer() .addNode({ a: 1, b: 2 }) .addPromise( async (c) => { diff --git a/iti/src/index.ts b/iti/src/index.ts index 43033b2..1fa3ec9 100644 --- a/iti/src/index.ts +++ b/iti/src/index.ts @@ -1,5 +1,5 @@ // Main lib -export { makeRoot, makeRoot as createContainer, Container } from "./iti" +export { createContainer, createContainer as makeRoot, Container } from "./iti" // Helper types export type { GetContainerFormat, UnPromisify, UnpackFunction } from "./_utils" diff --git a/iti/src/iti.ts b/iti/src/iti.ts index dcaddca..beb1b6b 100644 --- a/iti/src/iti.ts +++ b/iti/src/iti.ts @@ -415,6 +415,6 @@ export class Container< } } -export function makeRoot() { +export function createContainer() { return new Container() } diff --git a/iti/tests/container-get-values.spec.ts b/iti/tests/container-get-values.spec.ts index 1c3a6bb..13ebcb2 100644 --- a/iti/tests/container-get-values.spec.ts +++ b/iti/tests/container-get-values.spec.ts @@ -1,12 +1,12 @@ -import { makeRoot } from "../src/iti" +import { createContainer } from "../src/iti" function printTokenValue(token, value) { console.log(`Token: ${token} | ${value} -- of ${typeof value}`) } describe("Node.get()", () => { - let root: ReturnType + let root: ReturnType beforeEach(() => { - root = makeRoot() + root = createContainer() }) it("should return a value as a value", async () => { diff --git a/iti/tests/dispose-graph.ts.api.spec.ts b/iti/tests/dispose-graph.ts.api.spec.ts index a7a3a40..876a632 100644 --- a/iti/tests/dispose-graph.ts.api.spec.ts +++ b/iti/tests/dispose-graph.ts.api.spec.ts @@ -1,5 +1,5 @@ import { expect, jest, describe, beforeEach, it } from "@jest/globals" -import { makeRoot } from "../src" +import { createContainer } from "../src" import { wait } from "./_utils" import { A, X, B, C, D, L, K, E, M, F } from "./mock-graph" @@ -24,7 +24,7 @@ import { A, X, B, C, D, L, K, E, M, F } from "./mock-graph" └─────┘ └─────┘ └─────┘ └─────┘ */ function getGraph() { - return makeRoot() + return createContainer() .add({ a: () => new A(), x: () => new X() }) .add((ctx) => ({ b: () => new B(ctx.a), diff --git a/iti/tests/dispose.ts.api.spec.ts b/iti/tests/dispose.ts.api.spec.ts index 826f553..f10419e 100644 --- a/iti/tests/dispose.ts.api.spec.ts +++ b/iti/tests/dispose.ts.api.spec.ts @@ -1,12 +1,12 @@ import { expect, jest, describe, beforeEach, it } from "@jest/globals" -import { makeRoot } from "../src" +import { createContainer } from "../src" import { wait } from "./_utils" describe("Disposing: ", () => { - let root: ReturnType + let root: ReturnType beforeEach(() => { - root = makeRoot() + root = createContainer() }) class DB { @@ -101,13 +101,13 @@ describe("Disposing: ", () => { }) describe("Individual disposing: ", () => { - let root = makeRoot() + let root = createContainer() let disposerOfA = jest.fn() let node = root.add({ a: "A" }).addDisposer({ a: disposerOfA }) beforeEach(() => { disposerOfA.mockReset() - root = makeRoot() + root = createContainer() node = root.add({ a: "A" }).addDisposer({ a: disposerOfA }) }) @@ -143,10 +143,10 @@ describe("Individual disposing: ", () => { }) describe("Disposing complex async: ", () => { - let root = makeRoot() + let root = createContainer() beforeEach(() => { - root = makeRoot() + root = createContainer() }) class DB { @@ -164,7 +164,7 @@ describe("Disposing complex async: ", () => { it("should call async dispose with correct instances and correct times", async () => { const disposerDb = jest.fn() - const node = makeRoot() + const node = createContainer() .add({ db: () => new DB(), }) diff --git a/iti/tests/exotic.spec.ts b/iti/tests/exotic.spec.ts index 8971dd9..42720ac 100644 --- a/iti/tests/exotic.spec.ts +++ b/iti/tests/exotic.spec.ts @@ -1,11 +1,11 @@ -import { makeRoot } from "../src/iti" +import { createContainer } from "../src/iti" import { wait } from "./_utils" describe("Perf and exotic tests:", () => { - let root = makeRoot() + let root = createContainer() beforeEach(() => { - root = makeRoot() + root = createContainer() }) describe("Node get:", () => { diff --git a/iti/tests/getter.spec.ts b/iti/tests/getter.spec.ts index 7160f19..b4682c0 100644 --- a/iti/tests/getter.spec.ts +++ b/iti/tests/getter.spec.ts @@ -1,13 +1,13 @@ -import { makeRoot } from "../src/iti" +import { createContainer } from "../src/iti" import { provideAContainer } from "./mocks/container.a" import { provideBContainer } from "./mocks/container.b" describe("Node long chain async", () => { - let root: ReturnType + let root: ReturnType beforeEach(() => { - root = makeRoot() + root = createContainer() }) it("should test long chain", (cb) => { @@ -109,11 +109,11 @@ describe("Node long chain async", () => { }, 100) }) -describe("Node subscribeToContiner", () => { - let root: ReturnType +describe("Node subscribeToContainer", () => { + let root: ReturnType beforeEach(() => { - root = makeRoot() + root = createContainer() }) it("should subscribe to async container creation", (cb) => { @@ -242,10 +242,10 @@ describe("Node subscribeToContiner", () => { }) describe("Node getter", () => { - let root: ReturnType + let root: ReturnType beforeEach(() => { - root = makeRoot() + root = createContainer() }) it("should get nested conatainers", (cb) => { @@ -271,11 +271,11 @@ describe("Node getter", () => { }) describe("Node add", () => { - let root: ReturnType + let root: ReturnType let node: ReturnType function mockNode() { - return makeRoot().add({ + return createContainer().add({ a: "A", b: () => "B", c: async () => "C", @@ -283,7 +283,7 @@ describe("Node add", () => { }) } beforeEach(() => { - root = makeRoot() + root = createContainer() node = mockNode() }) @@ -374,10 +374,10 @@ describe("Node add", () => { }) describe("Node getContainerSet", () => { - let root: ReturnType + let root: ReturnType let node: ReturnType function mockNode() { - return makeRoot().add({ + return createContainer().add({ a: "A", b: () => "B", c: async () => "C", @@ -385,7 +385,7 @@ describe("Node getContainerSet", () => { }) } beforeEach(() => { - root = makeRoot() + root = createContainer() node = mockNode() }) diff --git a/iti/tests/mocks/_mock-app-container.ts b/iti/tests/mocks/_mock-app-container.ts index db83b10..d85ba6f 100644 --- a/iti/tests/mocks/_mock-app-container.ts +++ b/iti/tests/mocks/_mock-app-container.ts @@ -1,4 +1,4 @@ -import { makeRoot } from "../../src/iti" +import { createContainer } from "../../src/iti" import { provideAContainer } from "./container.a" import { provideBContainer } from "./container.b" @@ -6,7 +6,7 @@ import { provideCContainer } from "./container.c" export type MockAppNode = ReturnType export function getMainMockAppContainer() { - let node = makeRoot() + let node = createContainer() let k = node .add({ aCont: async () => provideAContainer() }) .add((c, node) => { diff --git a/iti/tests/tsd.getter.tsd-only.ts b/iti/tests/tsd.getter.tsd-only.ts index 8b5e02e..0148e1f 100644 --- a/iti/tests/tsd.getter.tsd-only.ts +++ b/iti/tests/tsd.getter.tsd-only.ts @@ -1,6 +1,6 @@ import { expectType, expectNotType } from "tsd" -import { makeRoot } from "../src/iti" +import { createContainer } from "../src/iti" enum UniqueResult { A, @@ -10,7 +10,7 @@ enum UniqueResult { } // results produced by an add should valid ;(async () => { - const node = makeRoot() + const node = createContainer() .add({ a: UniqueResult.A, b: () => UniqueResult.B, diff --git a/iti/tests/update.api.spec.ts b/iti/tests/update.api.spec.ts index ae91673..b615f04 100644 --- a/iti/tests/update.api.spec.ts +++ b/iti/tests/update.api.spec.ts @@ -1,11 +1,11 @@ -import { makeRoot } from "../src/iti" +import { createContainer } from "../src/iti" import { wait } from "./_utils" describe("Deleting and destructuring: ", () => { - let root: ReturnType + let root: ReturnType beforeEach(() => { - root = makeRoot() + root = createContainer() }) it("should be able to store null", () => { let r = root.add({ a: "A", b: null }) diff --git a/website/docs/1.intro.md b/website/docs/1.intro.md index 2c5ccaf..5dc878c 100644 --- a/website/docs/1.intro.md +++ b/website/docs/1.intro.md @@ -14,7 +14,7 @@ _This library doesn't try be scientifically correct. I just want to go home earl - **strongly typed:** has great IDE autocomplete and compile time check. Without any [manual type casting](https://github.com/inversify/InversifyJS/blob/master/wiki/container_api.md#containergettserviceidentifier-interfacesserviceidentifiert-t) - **non-invasive:** does not require imported `@decorators` or framework `extends` in your application business logic -- **lazy:** initialises your app modules and containers on demand +- **lazy:** initializes your app modules and containers on demand - **split chunks:** enables **[dynamic imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports)** via a [one liner](#dynamic-imports) thanks to a fully async core - **React friendly:** has useful **[React](https://github.com/molszanski/iti/tree/master/iti-react)** bindings to help you separate application business logic and a React view layer - **starter friendly:** works with starters like [Create React App](https://create-React-app.dev/) or [Next.js](https://nextjs.org/docs/getting-started) unlike existing libraries diff --git a/website/docs/4.usage.md b/website/docs/4.usage.md index e7df7e8..427c181 100644 --- a/website/docs/4.usage.md +++ b/website/docs/4.usage.md @@ -31,10 +31,10 @@ await root.getContainerSet(["oven", "userManual"]) // { userManual: '...', oven: await root.getContainerSet((c) => [c.userManual, c.oven]) // same as above // Subscribe to container changes -node.subscribeToContiner("oven", (oven) => {}) -node.subscribeToContinerSet(["oven", "kitchen"], ({ oven, kitchen }) => {}) +node.subscribeToContainer("oven", (oven) => {}) +node.subscribeToContainerSet(["oven", "kitchen"], ({ oven, kitchen }) => {}) // prettier-ignore -node.subscribeToContinerSet((c) => [c.kitchen], ({ oven, kitchen }) => {}) +node.subscribeToContainerSet((c) => [c.kitchen], ({ oven, kitchen }) => {}) node.on("containerUpdated", ({ key, newContainer }) => {}) node.on("containerUpserted", ({ key, newContainer }) => {}) node.on("containerDeleted", ({ key, newContainer }) => {}) @@ -43,7 +43,7 @@ node.on("containerDeleted", ({ key, newContainer }) => {}) **Writing** ```ts -let node1 = makeRoot() +let node1 = createContainer() .add({ userManual: "Please preheat before use", oven: () => new Oven(), diff --git a/website/docs/5.patterns-and-tips.md b/website/docs/5.patterns-and-tips.md index be47d84..b44487f 100644 --- a/website/docs/5.patterns-and-tips.md +++ b/website/docs/5.patterns-and-tips.md @@ -19,13 +19,13 @@ Prefer functions over eager init. Why? This will make the app lazy, hence faster ```ts // Good -makeRoot().add({ +createContainer().add({ eventBus: () => new EventBus(), userAuthService: () => new UserAuthService(), }) // Meh... -makeRoot().add({ +createContainer().add({ eventBus: new EventBus(), userAuthService: new UserAuthService(), }) @@ -38,7 +38,7 @@ In the second example we create instances on IoC container start. Which in most **Single Instance (a.k.a. Singleton)** ```ts -let node = makeRoot().add({ +let node = createContainer().add({ oven: () => new Oven(), }) node.get("oven") === node.get("oven") // true @@ -47,7 +47,7 @@ node.get("oven") === node.get("oven") // true **Transient** ```ts -let node = makeRoot().add({ +let node = createContainer().add({ oven: () => () => new Oven(), }) node.get("oven") === node.get("oven") // false @@ -73,9 +73,9 @@ export async function provideKitchenContainer() { ```ts // ./index.ts -import { makeRoot } from "iti" +import { createContainer } from "iti" import { provideKitchenContainer } from "./kitchen" -let node = makeRoot().add({ +let node = createContainer().add({ kitchen: async () => provideKitchenContainer(), }) @@ -91,7 +91,7 @@ await node.containers.kitchen.oven If you use callback pattern across your app, you will be able to mass rename your containerKeys using typescript. With strings, you will have to manually go through the app. But even if you use string literals compiler will not compile until you fix your rename manually across the app. ```ts -const node = makeRoot().addNode({ +const node = createContainer().addNode({ a: "A", b: "B", }) @@ -117,6 +117,6 @@ As a quick workaround we suggest: 1. **Reduce the number of `.add` steps** - this will help in most cases 2. **Reduce the number of unique tokens** - group some tokens together -3. **Create multiple containers** - it seems that your app is getting pretty big and complex. Maybe create to 2 containers via `makeRoot`? +3. **Create multiple containers** - it seems that your app is getting pretty big and complex. Maybe create to 2 containers via `createContainer`? 4. **Upgrade to TS 4.5 or higher** 5. **Optimize ITI** diff --git a/website/docs/6.getting-started.md.del b/website/docs/6.getting-started.md.del index 21f90d9..8cadda6 100644 --- a/website/docs/6.getting-started.md.del +++ b/website/docs/6.getting-started.md.del @@ -12,7 +12,7 @@ The best way to get started is to check [a CRA Pizza example](https://github.com Initial wiring ```ts -import { makeRoot } from "../../src/library.new-root-container" +import { createContainer } from "../../src/library.new-root-container" import { provideAContainer } from "./container.a" import { provideBContainer } from "./container.b" @@ -20,7 +20,7 @@ import { provideCContainer } from "./container.c" export type MockAppNode = ReturnType export function getMainMockAppContainer() { - return makeRoot() + return createContainer() .add({ aCont: async () => provideAContainer() }) .add((containers) => { return { diff --git a/website/docs/6_async_start-PART-2/main-example.ts b/website/docs/6_async_start-PART-2/main-example.ts index a14e674..580a751 100644 --- a/website/docs/6_async_start-PART-2/main-example.ts +++ b/website/docs/6_async_start-PART-2/main-example.ts @@ -1,4 +1,4 @@ -import { makeRoot } from "iti" +import { createContainer } from "iti" // prettier-ignore interface Logger { info: (msg: string) => void } // prettier-ignore @@ -43,7 +43,7 @@ export async function runMyApp() { } export async function runMyApp2() { - const root = makeRoot() + const root = createContainer() .add({ logger: () => process.env.NODE_ENV === "production" diff --git a/website/docs/6_async_start-PART-2/main/app.ts b/website/docs/6_async_start-PART-2/main/app.ts index bb0e799..e473385 100644 --- a/website/docs/6_async_start-PART-2/main/app.ts +++ b/website/docs/6_async_start-PART-2/main/app.ts @@ -1,5 +1,5 @@ // Part 2: ITI boilerplate. Manual DI alternative -import { makeRoot } from "iti" +import { createContainer } from "iti" import { PaymentService, AuthService, @@ -7,7 +7,7 @@ import { } from "./business-logic" import { PinoLogger, ConsoleLogger } from "./loggers" -export const app = makeRoot() +export const app = createContainer() .add({ // Add token `logger` and assign some logger instance logger: () => diff --git a/website/docs/9.api.md b/website/docs/9.api.md index d2bd447..50cb269 100644 --- a/website/docs/9.api.md +++ b/website/docs/9.api.md @@ -50,12 +50,12 @@ await kitchenApp.containers.kitchen ## API documentation JS / TS -### `makeRoot` Setting app root +### `createContainer` Setting app root ```ts -import { makeRoot } from "../../library.root-container" +import { createContainer } from "../../library.root-container" export function getMainMockAppContainer() { - return makeRoot().add({ kitchen: () => new Kitchen(/* deps */) }) + return createContainer().add({ kitchen: () => new Kitchen(/* deps */) }) } ``` diff --git a/website/docs/async-di/5.iti.mdx b/website/docs/async-di/5.iti.mdx index 3bfcc17..3171b52 100644 --- a/website/docs/async-di/5.iti.mdx +++ b/website/docs/async-di/5.iti.mdx @@ -8,7 +8,7 @@ tags: # ITI ```ts -import { makeRoot } from "iti" +import { createContainer } from "iti" // prettier-ignore interface Logger { info: (msg: string) => void } // prettier-ignore @@ -40,7 +40,7 @@ class PaymentService { } export async function runMyApp() { - const root = makeRoot() + const root = createContainer() .add({ logger: () => process.env.NODE_ENV === "production" diff --git a/website/docs/basic-di/5.iti.mdx b/website/docs/basic-di/5.iti.mdx index 81e22e8..336a6e9 100644 --- a/website/docs/basic-di/5.iti.mdx +++ b/website/docs/basic-di/5.iti.mdx @@ -5,7 +5,7 @@ sidebar_position: 2 # ITI DI ```ts -import { makeRoot } from "iti" +import { createContainer } from "iti" export interface Logger { info: (msg: string) => void warn: (msg: string) => void @@ -40,7 +40,7 @@ export class PaymentService { } } -const root = makeRoot() +const root = createContainer() .add({ logger: () => process.env.NODE_ENV === "production" diff --git a/website/docs/basic-di/6.iti-vs-pure.mdx b/website/docs/basic-di/6.iti-vs-pure.mdx index 0ccb845..6915aa5 100644 --- a/website/docs/basic-di/6.iti-vs-pure.mdx +++ b/website/docs/basic-di/6.iti-vs-pure.mdx @@ -65,7 +65,7 @@ paymentService.sendMoney() ```tsx title="./src/app.ts" -const root = makeRoot() +const root = createContainer() .add({ logger: () => process.env.NODE_ENV === "production" diff --git a/website/docs/examples/circular-dependency.ts b/website/docs/examples/circular-dependency.ts index 75bfa36..a772922 100644 --- a/website/docs/examples/circular-dependency.ts +++ b/website/docs/examples/circular-dependency.ts @@ -1,4 +1,4 @@ -import { makeRoot } from "iti" +import { createContainer } from "iti" /* // Part 1: You can create a circular dependency @@ -27,7 +27,7 @@ class E { } // Part 2: You can't express a circular dependency because of typescript checks -makeRoot() +createContainer() .add((ctx) => ({ a: () => new A(), })) diff --git a/website/docs/with-react/configuration.md b/website/docs/with-react/configuration.md index 6892285..08e5a44 100644 --- a/website/docs/with-react/configuration.md +++ b/website/docs/with-react/configuration.md @@ -7,10 +7,10 @@ sidebar_position: 3 Basically, we create an ITI instance, add it to `React.Context` and generate fetch hooks. ```tsx title="./src/_containers/main-app" -import { makeRoot } from "iti" +import { createContainer } from "iti" export const mainApp = () => - makeRoot().add(() => ({ + createContainer().add(() => ({ auth: async () => { const res = await fetch("/api/profile") return {