Skip to content

Commit

Permalink
Update issue templates (#31)
Browse files Browse the repository at this point in the history
* rename: makeRoot -> createContainer

* fix spelling

* update readme

* Update issue templates
  • Loading branch information
molszanski authored Oct 8, 2022
1 parent 4042e83 commit 7228a74
Show file tree
Hide file tree
Showing 32 changed files with 139 additions and 107 deletions.
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions examples/cra/src/containers/_root.store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeRoot } from "iti"
import { createContainer } from "iti"

import { provideAContainer } from "./container.a"
import { provideAuthContainer } from "./container.auth"
Expand All @@ -12,7 +12,7 @@ import { provideFatLib2 } from "./container.fat-lib2"

export type PizzaAppCoreContainer = ReturnType<typeof pizzaAppCore>
export function pizzaAppCore() {
return makeRoot()
return createContainer()
.add(() => ({
auth: async () => provideAuthContainer(),
}))
Expand Down
14 changes: 7 additions & 7 deletions examples/node-cli/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from "lodash"
import { makeRoot } from "iti"
import { createContainer } from "iti"

// Step 1: Your application logic stays clean
class Oven {
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions examples/vite-app/src/_bl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeRoot } from "iti"
import { createContainer } from "iti"

export class A {}
export class B {
Expand All @@ -8,7 +8,7 @@ export class C {
constructor(a: A, b: B) {}
}

export const app = makeRoot()
export const app = createContainer()
.add(() => ({
a: () => new A(),
}))
Expand Down
2 changes: 1 addition & 1 deletion iti-react/notes-and-ideas.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion iti-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions iti-react/tests/mocks/_mock-app-container.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { makeRoot } from "iti"
import { createContainer } from "iti"

import { provideAContainer } from "./container.a"
import { provideBContainer } from "./container.b"
import { provideCContainer } from "./container.c"

export type MockAppNode = ReturnType<typeof getMainMockAppContainer>
export function getMainMockAppContainer() {
let node = makeRoot()
let node = createContainer()
let k = node
.upsert({ aCont: async () => provideAContainer() })
.upsert((c) => {
Expand Down
41 changes: 20 additions & 21 deletions iti/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

# Iti

<h4>1kB Dependency Injection Library for Typescript and React with a unique support of <strong>async flow</strong></h4>
<h4>~1kB Dependency Injection Library for Typescript and React with a unique <strong>async flow</strong> support</h4>

<p align="center">
<a href="https://github.com/molszanski/iti/actions?query=branch%3Amaster"><img src="https://github.com/molszanski/iti/actions/workflows/lib-test.yml/badge.svg" alt="CI Status"></a>
<a href="https://www.npmjs.org/package/iti"><img src="https://img.shields.io/npm/v/iti.svg" alt="npm version"></a>
<a href="https://unpkg.com/iti/dist/iti.modern.js"><img src="https://img.badgesize.io/https://unpkg.com/iti/dist/iti.modern.js?compression=gzip" alt="gzip"></a>
<!-- Manually checked at b1683832 on OCT 8 2022-->
<a href="https://dashboard.stryker-mutator.io/reports/github.com/molszanski/iti/master"><img src="https://img.shields.io/badge/coverage-98.6%25-brightgreen" alt="Coverage"></a>
<a href="https://dashboard.stryker-mutator.io/reports/github.com/molszanski/iti/master"><img src="https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fmolszanski%2Fiti%2Fmaster" alt="Mutation Score"></a>
</p>

Expand Down Expand Up @@ -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<void> {
// ... disconnect
}
connect(): Promise<void> {}
disconnect(): Promise<void> {}
}

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
Expand Down
2 changes: 1 addition & 1 deletion iti/notes-and-ideas.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion iti/src/index.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion iti/src/iti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,6 @@ export class Container<
}
}

export function makeRoot() {
export function createContainer() {
return new Container()
}
6 changes: 3 additions & 3 deletions iti/tests/container-get-values.spec.ts
Original file line number Diff line number Diff line change
@@ -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<typeof makeRoot>
let root: ReturnType<typeof createContainer>

beforeEach(() => {
root = makeRoot()
root = createContainer()
})

it("should return a value as a value", async () => {
Expand Down
4 changes: 2 additions & 2 deletions iti/tests/dispose-graph.ts.api.spec.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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),
Expand Down
16 changes: 8 additions & 8 deletions iti/tests/dispose.ts.api.spec.ts
Original file line number Diff line number Diff line change
@@ -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<typeof makeRoot>
let root: ReturnType<typeof createContainer>

beforeEach(() => {
root = makeRoot()
root = createContainer()
})

class DB {
Expand Down Expand Up @@ -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 })
})

Expand Down Expand Up @@ -143,10 +143,10 @@ describe("Individual disposing: ", () => {
})

describe("Disposing complex async: ", () => {
let root = makeRoot()
let root = createContainer()

beforeEach(() => {
root = makeRoot()
root = createContainer()
})

class DB {
Expand All @@ -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(),
})
Expand Down
6 changes: 3 additions & 3 deletions iti/tests/exotic.spec.ts
Original file line number Diff line number Diff line change
@@ -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:", () => {
Expand Down
Loading

0 comments on commit 7228a74

Please sign in to comment.