Skip to content

Instantly share code, notes, and snippets.

View Odonno's full-sized avatar
🏠
Working from home

David Bottiau Odonno

🏠
Working from home
View GitHub Profile
@Odonno
Odonno / realtime.effects.ts
Created July 27, 2019 15:51
ngrx/signalr - initHubWithOfHubOperator
initHubOne$ = createEffect(() =>
this.actions$.pipe(
ofType(SIGNALR_HUB_UNSTARTED),
ofHub(hub1),
mergeMapHubToAction(({ action, hub }) => {
// TODO : init hub 1
})
)
);
@Odonno
Odonno / create-hubs.ts
Created July 27, 2019 15:51
ngrx/signalr - createMultipleHubs
// simplified hub creation
const dispatchHubCreation = (hub) => this.store.dispatch(createSignalRHub(hub));
const hub1 = {}; // define hubName and url
const hub2 = {}; // define hubName and url
const hub3 = {}; // define hubName and url
dispatchHubCreation(hub1);
dispatchHubCreation(hub2);
dispatchHubCreation(hub3);
@Odonno
Odonno / realtime.effects.ts
Created July 27, 2019 15:49
ngrx/signalr - sendEvent
sendEvent$ = createEffect(() =>
this.actions$.pipe(
ofType(sendEvent), // TODO : create a custom action
mergeMap(({ params }) => {
const hub = findHub(timeHub);
if (!hub) {
return of(hubNotFound(timeHub));
}
// TODO : send event to the hub
@Odonno
Odonno / realtime.effects.ts
Created July 27, 2019 15:48
ngrx/signalr - initSingleHub
initRealtime$ = createEffect(() =>
this.actions$.pipe(
ofType(SIGNALR_HUB_UNSTARTED),
mergeMapHubToAction(({ hub }) => {
// TODO : add event listeners
const whenEvent$ = hub.on('eventName').pipe(
map(x => createAction(x))
);
return merge(
@Odonno
Odonno / realtime.effects.ts
Created July 27, 2019 15:47
ngrx/signalr - whenDisconnected
whenDisconnected$ = createReconnectEffect(this.actions$, 10 * 1000);
@Odonno
Odonno / start-hub.ts
Created July 27, 2019 15:46
ngrx/signalr - startHub
store.dispatch(startSignalRHub(hubDefinition));
@Odonno
Odonno / create-hub.ts
Created July 27, 2019 15:45
ngrx/signalr - createHub
const hubDefinition = {
hubName: 'hub name',
url: 'https://localhost/path'
};
store.dispatch(createSignalRHub(hubDefinition));
@Odonno
Odonno / app.module.ts
Created July 27, 2019 15:43
ngrx/signalr - App module
@NgModule({
...,
imports: [
StoreModule.forRoot({ signalr: signalrReducer }),
EffectsModule.forRoot([SignalREffects, ...])
],
...
})
export class AppModule { }
@Odonno
Odonno / GraphApiService.cs
Created July 14, 2019 11:48
Azure AD - MS Graph - Search users
public async Task<List<User>> SearchUsersAsync(string search, int limit)
{
var client = new GraphServiceClient(_msGraphAuthenticationProvider);
var users = new List<User>();
var currentReferencesPage = await client.Users
.Request()
.Top(limit)
.Filter($"startsWith(displayName, '{search}') or startswith(mail, '{search}')")
.GetAsync();
@Odonno
Odonno / GraphApiService.cs
Created July 14, 2019 11:47
Azure AD - MS Graph - Get user profile
public async Task<User> GetUserProfileAsync()
{
var client = new GraphServiceClient(_msGraphAuthenticationProvider);
return await client.Me.Request().GetAsync();
}