This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type StoreContextState = { | |
todos: Todo[]; | |
loadTodos: () => Promise<void>; | |
createTodo: (content: string) => Promise<void>; | |
changeContent: (todo: Todo, content: string) => void; | |
updateTodo: (id: number, content: string) => Promise<void>; | |
deleteTodo: (id: number) => Promise<void>; | |
}; | |
const StoreContext = createContext<StoreContextState>({} as StoreContextState); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ChannelReader<Weather> RealtimeWeather() | |
{ | |
return _realtimeValuesService.Observe() | |
.ToBufferedStream(Context.ConnectionAborted); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ChannelReader<Weather> RealtimeWeather() | |
{ | |
return _realtimeValuesService.Observe() | |
.ToNewestValueStream(Context.ConnectionAborted); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// listen to realtime event | |
fromStream<number>(connection, "realtimeWeather") | |
.subscribe({ | |
next: value => setWeather(value), | |
error: err => displayUserError(err), | |
complete: () => console.log('No more weather?') | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const count$ = combineLatest(increment$, decrement$).pipe( | |
scan((acc, curr) => acc + curr, 0), | |
startWith(0) | |
); // basic counter with increment and decrement features | |
// send realtime event | |
sendStream("setCount", count$); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Read the client-to-server stream | |
private async Task SetCount(IAsyncEnumerable<int> stream) | |
{ | |
await foreach (int item in stream.WithCancellation(Context.ConnectionAborted)) | |
{ | |
Console.WriteLine(item); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basic implementation of server-to-client | |
public ChannelReader<Weather> RealtimeWeather() | |
{ | |
var channel = Channel.CreateUnbounded<Weather>(); | |
_ = WriteItemsAsync(channel.Writer, count, delay); | |
return channel.Reader; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const offline$ = fromEvent(window, 'offline').pipe(map(_ => false)); | |
const online$ = fromEvent(window, 'online').pipe(map(_ => true)); | |
const hasInternetConnection$ = merge( | |
of(navigator.onLine), | |
offline$, | |
online$ | |
); | |
const hubsStatuses$ = this.store.pipe( | |
select(selectHubsStatuses) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseSignalRStoreState { | |
hubStatuses: SignalRHubStatus[]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type SignalRHubState = | |
| typeof unstarted | |
| typeof connected | |
| typeof disconnected; | |
type SignalRHubStatus = { | |
hubName: string; | |
url: string; | |
state: SignalRHubState; | |
}; |