Skip to content

Commit

Permalink
docs: Format code in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jontze committed Jun 10, 2024
1 parent e31eb3e commit eb8bcf9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 70 deletions.
61 changes: 26 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,35 @@ or any other Node.JS package manager.
1. Fetch your Config and Set in the Store

```typescript
import { bootstrapApplication } from "@angular/platform-browser";
import { setRemoteConfig } from "@jontze/ng-remote-config";
import { bootstrapApplication } from '@angular/platform-browser';
import { setRemoteConfig } from '@jontze/ng-remote-config';

import { appConfig } from "./app/app.config";
import { AppComponent } from "./app/app.component";
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';

Promise.all([
fetch("/assets/config.json").then((res) => res.json())
fetch('/assets/config.json')
.then((res) => res.json())
.then((config) => setRemoteConfig(config)),
fetch("/assets/features.json").then((res) => res.json())
.then((features) => setRemoteConfig(features, "features")),
]).then(() => bootstrapApplication(AppComponent, appConfig))
fetch('/assets/features.json')
.then((res) => res.json())
.then((features) => setRemoteConfig(features, 'features')),
])
.then(() => bootstrapApplication(AppComponent, appConfig))
.catch((err) => console.error(err));
```

2. Provide the Configuration in DI

```typescript
import { ApplicationConfig, provideZoneChangeDetection } from "@angular/core";
import { provideRouter } from "@angular/router";
import { provideConfig } from "@jontze/ng-remote-config";
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideConfig } from '@jontze/ng-remote-config';

import { appRoutes } from "./app.routes";
import { appRoutes } from './app.routes';

export const appConfig: ApplicationConfig = {
providers: [
provideRouter(appRoutes),
provideConfig(),
],
providers: [provideRouter(appRoutes), provideConfig()],
};
```

Expand All @@ -94,44 +94,35 @@ interface FeatureFlags {

@Component({
standalone: true,
selector: "app-root",
templateUrl: "./app.component.html",
styleUrl: "./app.component.css",
selector: 'app-root',
templateUrl: './app.component.html',
styleUrl: './app.component.css',
})
export class AppComponent implements OnInit {
private readonly configService = inject(ConfigService);

ngOnInit(): void {
console.debug(
"ConfigService:",
this.configService.getConfig<YourConfigType>(),
);
console.debug(
"ConfigService:",
this.configService.getConfig<FeatureFlags>("features"),
);
console.debug('ConfigService:', this.configService.getConfig<YourConfigType>());
console.debug('ConfigService:', this.configService.getConfig<FeatureFlags>('features'));
}
}
```

4. Outside of the DI Context: Access the Configuration via the Store

```typescript
import { ApplicationConfig } from "@angular/core";
import { provideRouter } from "@angular/router";
import { getRemoteConfig } from "@jontze/ng-remote-config";
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { getRemoteConfig } from '@jontze/ng-remote-config';

import { appRoutes } from "./app.routes";
import { appRoutes } from './app.routes';

interface ApiConfig {
apiUrl: string;
}

export const appConfig: ApplicationConfig = {
providers: [
provideRouter(appRoutes),
provideSomeAPI({ url: getRemoteConfig<ApiConfig>().apiUrl }),
],
providers: [provideRouter(appRoutes), provideSomeAPI({ url: getRemoteConfig<ApiConfig>().apiUrl })],
};
```

Expand Down
61 changes: 26 additions & 35 deletions libs/ng-remote-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,35 @@ or any other Node.JS package manager.
1. Fetch your Config and Set in the Store

```typescript
import { bootstrapApplication } from "@angular/platform-browser";
import { setRemoteConfig } from "@jontze/ng-remote-config";
import { bootstrapApplication } from '@angular/platform-browser';
import { setRemoteConfig } from '@jontze/ng-remote-config';

import { appConfig } from "./app/app.config";
import { AppComponent } from "./app/app.component";
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';

Promise.all([
fetch("/assets/config.json").then((res) => res.json())
fetch('/assets/config.json')
.then((res) => res.json())
.then((config) => setRemoteConfig(config)),
fetch("/assets/features.json").then((res) => res.json())
.then((features) => setRemoteConfig(features, "features")),
]).then(() => bootstrapApplication(AppComponent, appConfig))
fetch('/assets/features.json')
.then((res) => res.json())
.then((features) => setRemoteConfig(features, 'features')),
])
.then(() => bootstrapApplication(AppComponent, appConfig))
.catch((err) => console.error(err));
```

2. Provide the Configuration in DI

```typescript
import { ApplicationConfig, provideZoneChangeDetection } from "@angular/core";
import { provideRouter } from "@angular/router";
import { provideConfig } from "@jontze/ng-remote-config";
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideConfig } from '@jontze/ng-remote-config';

import { appRoutes } from "./app.routes";
import { appRoutes } from './app.routes';

export const appConfig: ApplicationConfig = {
providers: [
provideRouter(appRoutes),
provideConfig(),
],
providers: [provideRouter(appRoutes), provideConfig()],
};
```

Expand All @@ -94,44 +94,35 @@ interface FeatureFlags {

@Component({
standalone: true,
selector: "app-root",
templateUrl: "./app.component.html",
styleUrl: "./app.component.css",
selector: 'app-root',
templateUrl: './app.component.html',
styleUrl: './app.component.css',
})
export class AppComponent implements OnInit {
private readonly configService = inject(ConfigService);

ngOnInit(): void {
console.debug(
"ConfigService:",
this.configService.getConfig<YourConfigType>(),
);
console.debug(
"ConfigService:",
this.configService.getConfig<FeatureFlags>("features"),
);
console.debug('ConfigService:', this.configService.getConfig<YourConfigType>());
console.debug('ConfigService:', this.configService.getConfig<FeatureFlags>('features'));
}
}
```

4. Outside of the DI Context: Access the Configuration via the Store

```typescript
import { ApplicationConfig } from "@angular/core";
import { provideRouter } from "@angular/router";
import { getRemoteConfig } from "@jontze/ng-remote-config";
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { getRemoteConfig } from '@jontze/ng-remote-config';

import { appRoutes } from "./app.routes";
import { appRoutes } from './app.routes';

interface ApiConfig {
apiUrl: string;
}

export const appConfig: ApplicationConfig = {
providers: [
provideRouter(appRoutes),
provideSomeAPI({ url: getRemoteConfig<ApiConfig>().apiUrl }),
],
providers: [provideRouter(appRoutes), provideSomeAPI({ url: getRemoteConfig<ApiConfig>().apiUrl })],
};
```

Expand Down

0 comments on commit eb8bcf9

Please sign in to comment.