Skip to content

Commit

Permalink
chore: rename into FlatProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletFlash committed Nov 10, 2024
1 parent bd0c57b commit 48db048
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
CURRENT_VERSION=$(grep --only-matching --perl-regexp '"version":\s*"\K[^"]+' package.json)
TARGET_VERSION="$CURRENT_VERSION-sha.${{github.sha}}"
if pnpm view multiprovider@"${TARGET_VERSION}" > /dev/null 2>&1; then
if pnpm view flat-provider@"${TARGET_VERSION}" > /dev/null 2>&1; then
echo "Version already exists. Skipping publish."
else
pnpm version ${TARGET_VERSION}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Multiprovider
# Flat Provider

A simple and type-safe multiprovider implementation for React applications.

Expand Down Expand Up @@ -27,12 +27,12 @@ export default function Layout({ children }: PropsWithChildren): ReactElement {
#### Into this:

```tsx
import { Multiprovider } from "multiprovider";
import { FlatProvider } from "flat-provider";

export default function Layout({ children }: PropsWithChildren): ReactElement {
// ...

return Multiprovider
return FlatProvider
.append(UserTrackingProvider, { apiKey: process.env.TRACKING_API_KEY })
.append(AuthProvider, { session })
.append(UiKitProvider)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "multiprovider",
"name": "flat-provider",
"version": "0.1.0",
"private": true,
"repository": {
"type": "git",
"url": "git+https://github.com/ScarletFlash/multiprovider.git"
"url": "git+https://github.com/ScarletFlash/flat-provider.git"
},
"bugs": {
"url": "https://github.com/ScarletFlash/multiprovider/issues"
"url": "https://github.com/ScarletFlash/flat-provider/issues"
},
"author": {
"name": "Fedor Usakov",
Expand Down
12 changes: 6 additions & 6 deletions src/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PropsWithChildren,
useContext,
} from "react";
import { Multiprovider } from "./index";
import { FlatProvider } from "./index";

const testId: string = "test-wrapper";

Expand All @@ -18,7 +18,7 @@ it("should return children as is if no providers are set", () => {

render(
<section data-testid={testId}>
{Multiprovider.getLayout(<>{expectedInnerHtml}</>)}
{FlatProvider.getLayout(<>{expectedInnerHtml}</>)}
</section>
);

Expand Down Expand Up @@ -64,9 +64,9 @@ it("should render React context providers in the correct order", () => {
<section data-testid={testId}>
{providers
.reduce(
(multiproviderRef: Multiprovider, currentProvider: FC) =>
multiproviderRef.append(currentProvider),
new Multiprovider()
(flatProvider: FlatProvider, currentProvider: FC) =>
flatProvider.append(currentProvider),
new FlatProvider()
)
.getLayout()}
</section>
Expand Down Expand Up @@ -103,7 +103,7 @@ it("should correctly handle props", () => {

render(
<section data-testid={testId}>
{Multiprovider.append(ComponentWithProps, {
{FlatProvider.append(ComponentWithProps, {
payload: { timestamp },
})
.append(ComponentWithoutProps)
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ProviderWithProps<

type Children = Pick<PropsWithChildren, "children">["children"];

export class Multiprovider {
export class FlatProvider {
readonly #providers: ProviderWithProps[] = [];

public append(component: FC): this;
Expand All @@ -50,20 +50,20 @@ export class Multiprovider {
);
}

public static append(component: FC): Multiprovider;
public static append(component: FC): FlatProvider;
public static append<P extends PropsWithChildren>(
component: FC<P>,
props: Omit<P, "children">
): Multiprovider;
): FlatProvider;
public static append<P extends PropsWithChildren, C extends ComponentType<P>>(
component: C,
props?: ComponentPropsWithoutChildren<C>
): Multiprovider;
public static append(component: any, props?: any): Multiprovider {
return new Multiprovider().append(component, props);
): FlatProvider;
public static append(component: any, props?: any): FlatProvider {
return new FlatProvider().append(component, props);
}

public static getLayout(children?: Children): ReactNode {
return new Multiprovider().getLayout(children);
return new FlatProvider().getLayout(children);
}
}

0 comments on commit 48db048

Please sign in to comment.