Skip to content

Commit

Permalink
feat: update installation guide to remove RxJS as a mandatory depende…
Browse files Browse the repository at this point in the history
…ncy and clarify optional usage
  • Loading branch information
dawit-io committed Dec 28, 2024
1 parent f9013ee commit 334799b
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions docs/guide/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
## Requirements
- Node.js (version 16 or higher)
- npm, yarn, or pnpm package manager
- RxJS (version 7 or higher) for Observable support

## Package Installation

You can install IT-Faker using your preferred package manager:

### npm
```bash
npm install @italia-tools/faker rxjs
npm install @italia-tools/faker
```

### yarn
```bash
yarn add @italia-tools/faker rxjs
yarn add @italia-tools/faker
```

### pnpm
```bash
pnpm add @italia-tools/faker rxjs
pnpm add @italia-tools/faker
```

## TypeScript Configuration
Expand All @@ -43,21 +42,16 @@ IT-Faker includes TypeScript definitions out of the box. No additional types pac
### ES Modules (Recommended)
```typescript
import { itFaker } from '@italia-tools/faker';
// For Observable support
import { Observable } from 'rxjs';
```

### CommonJS
```javascript
const { itFaker } = require('@italia-tools/faker');
// For Observable support
const { Observable } = require('rxjs');
```

## Verification
To verify your installation, you can run these simple tests:
To verify your installation, you can run this simple test:

### Using Promises
```typescript
import { itFaker } from '@italia-tools/faker';

Expand All @@ -70,16 +64,24 @@ async function test() {
test();
```

### Using Observables
## Optional RxJS Support

If you need reactive programming support, you can install RxJS as an optional dependency:

```bash
npm install rxjs
```

Then you can use the Observable-based API:

```typescript
import { itFaker } from '@italia-tools/faker';
import { Observable } from 'rxjs';

// Should generate an Italian name
itFaker.itPerson.firstName$().subscribe(name => {
console.log(name);
});
```

## Framework Integration

### Angular
Expand All @@ -89,10 +91,11 @@ import { Component } from '@angular/core';
import { itFaker } from '@italia-tools/faker';

@Component({
// ...
selector: 'app-person',
template: '{{ italianName$ | async }}'
})
export class MyComponent {
italianNames$ = itFaker.itPerson.firstName$();
export class PersonComponent {
italianName$ = itFaker.itPerson.firstName$();
}
```

Expand All @@ -102,17 +105,22 @@ You can use either Promises or Observables based on your needs:
import { useState, useEffect } from 'react';
import { itFaker } from '@italia-tools/faker';

// Using Promises
const [name, setName] = useState('');
useEffect(() => {
itFaker.itPerson.firstName().then(setName);
}, []);

// Using Observables
useEffect(() => {
const subscription = itFaker.itPerson.firstName$().subscribe(setName);
return () => subscription.unsubscribe();
}, []);
function PersonName() {
const [name, setName] = useState('');

// Using Promises
useEffect(() => {
itFaker.itPerson.firstName().then(setName);
}, []);

// Using Observables
useEffect(() => {
const subscription = itFaker.itPerson.firstName$().subscribe(setName);
return () => subscription.unsubscribe();
}, []);

return <div>{name}</div>;
}
```

## Next Steps
Expand Down

0 comments on commit 334799b

Please sign in to comment.