Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft - Framework integration #1980

Merged
merged 16 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ This example shows how you can use the slots in the Modal component

```typescript
import { AfterViewInit, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, ViewChild } from '@angular/core';
import { FormsModule } from '@angular/forms';

@Component({
selector: 'modal-example',
Expand All @@ -296,7 +295,6 @@ template: `
`,
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [FormsModule],
})
export class ModalExampleComponent implements AfterViewInit {
@ViewChild('modal') modalRef!: ElementRef;
Expand All @@ -310,6 +308,71 @@ export class ModalExampleComponent implements AfterViewInit {
}
```

## Dependency Injection

Foundation UI has a suite of services that can be added to your application via dependency injection.

If you want to use the Connect service, the best approach is to create an injection token and register it in your app module.
patrickoneill-genesis marked this conversation as resolved.
Show resolved Hide resolved

**connect-service.ts**

```ts
import { Connect, getConnect } from '@genesislcap/foundation-comms';
import { InjectionToken } from '@angular/core';

export const connectService = getConnect();
export const CONNECT_TOKEN = new InjectionToken<Connect>('Logger');
```

**app.module.ts**
```ts
@NgModule({
...
providers: [
{ provide: CONNECT_TOKEN, useValue: connectService },
...
],
...
})
```

**your-angular-component.ts**

After adding the connect service to your module providers using an injection token, you can add it to any class using Angular DI.

This component will use the Connect `snapshot` method to retrieve data from a dataserver query `ALL_TRADES` and render it in a list.

```typescript
import { OnInit, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { NgForOf } from '@angular/common';
import { Connect } from '@genesislcap/foundation-comms';
import { CONNECT_TOKEN } from 'path/to/connect.service';

@Component({
selector: 'di-example',
template: `
<ul>
<li *ngFor="let item of data">Direction: {{item.TRADE_ID}} Quantity: {{item.QUANTITY}} Ticker: {{item.TICKER}}</li>
</ul>`,
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [ NgForOf ],

})
export class DIExampleComponent implements OnInit {
constructor(@Inject(CONNECT_TOKEN) private connect: Connect) {}

async ngOnInit() {
const response = await this.connect.snapshot('ALL_TRADES')

if (response.ROW?.length) {
this.data = response.ROW;
}
}
}
```

patrickoneill-genesis marked this conversation as resolved.
Show resolved Hide resolved

### Design tokens

Design tokens are declared in the **src/styles/design-tokens.json** file. They offer an effective way to manage and apply styles in your application in a consistent and maintainable manner.
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the same comments I left on the Angular page apply here too

Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,76 @@ export function MyComponent() {
}
```

## Dependency Injection

Foundation UI has a suite of services that can be added to your application via dependency injection.

If you want to use the Connect service, the best approach is to create a class to resolve the dependency injection boilerplate and export it.

**connect-service.ts**
```ts
import { DI } from '@microsoft/fast-foundation';
import { Connect } from '@genesislcap/foundation-comms';
import { API_DATA } from '../config';

class ConnectService {
private container = DI.getOrCreateDOMContainer();
private connect: Connect = this.container.get(Connect);

getContainer() {
return this.container;
}

getConnect() {
return this.connect;
}

isConnected() {
return this.connect.isConnected;
}

init() {
return this.connect.connect(API_DATA.URL);
}
}

export const connectService = new ConnectService();
```

**your-react-component.ts**

This component will use the Connect `snapshot` method to retrieve data from a dataserver query `ALL_TRADES` and render it in a list.

```ts
import React, { useState, useEffect } from 'react';
import { connectService } from './connect.service'; // your file location

export function YourReactComponent {

const [data, setData] = useState([]);

useEffect(() => {
const getData = async () => {
const response = await connectService.getConnect().snapshot('ALL_TRADES')

if (response.ROW?.length) {
setData(response.ROW);
}
}

getData();
}, []);

return (
<ul>
{data.map((item) => (
<li>Direction: {item.DIRECTION} Quantity: {item.QUANTITY} Ticker: {item.TICKER}</li>
))}
</ul>
);
}
```

### Design tokens

Design tokens are declared in the **src/styles/design-tokens.json** file. They offer an effective way to manage and apply styles in your application in a consistent and maintainable manner.
Expand Down