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
| import 'package:flutter/material.dart'; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| // This widget is the root of your application. | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Flutter Demo', |
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
| import 'package:flutter/material.dart'; | |
| import 'package:provider/provider.dart'; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Flutter Demo', |
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
| // thanks to assistance from Martin Kavik and discord/rust @kpreid | |
| use std::collections::HashMap; | |
| pub type Value = i32; | |
| pub type Result = std::result::Result<(), Error>; | |
| #[derive(Debug, PartialEq, Eq)] | |
| pub enum Error { | |
| DivisionByZero, |
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
| // Implements https://exercism.org/tracks/rust/exercises/forth. Errors on line 168. | |
| use std::cell::RefCell; | |
| use std::collections::HashMap; | |
| pub type Value = i32; | |
| pub type Result = std::result::Result<(), Error>; | |
| #[derive(Debug, PartialEq, Eq)] | |
| pub enum Error { |
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
| import 'dart:async'; | |
| import 'package:flutter/material.dart'; | |
| import 'package:provider/provider.dart'; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| const appTitle = 'FutureProvider Demo'; |
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 async function bindMainApi<T extends ElectronMainApi<T>>( | |
| apiClassName: string | |
| ): Promise<MainApiBinding<T>> { | |
| // Use IPC to get a list of the API's methods from the main process. | |
| const methodNames = await requestApiMethods<T>(apiClassName); | |
| // boundApi will hold the binding, after we've added each method. | |
| const boundApi = {} as MainApiBinding<T>; | |
| // For each method name reported to be in the API... |
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
| // This associates the name of each API with a list of the API's methods. | |
| const exposedApis: Record<string, string[]> = {}; | |
| function exposeMainApi<T extends ElectronMainApi<T>>(mainApi: T): void { | |
| const apiClassName = mainApi.constructor.name; | |
| const methodNames: string[] = []; | |
| // For each property of mainApi... | |
| for (const methodName of getPropertyNames(mainApi)) { | |
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
| function exposeMainApi<T extends ElectronMainApi<T>>(mainApi: T): void { | |
| /* ... */ | |
| } |
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 PublicProperty<P> = P extends `_${string}` | |
| ? never | |
| : (P extends `#${string}` ? never : P); | |
| export type ElectronMainApi<T> = { | |
| [K in PublicProperty<keyof T>]: (...args: any[]) => Promise<any>; | |
| }; |
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
| import type { MainApi1 } from '../backend/apis/main_api_1.ts'; | |
| async function doSomething() { | |
| const mainApi1 = await bindMainApi<MainApi1>("MainApi1"); | |
| let result = await mainApi1.methodB(); | |
| /* ... */ | |
| } |
NewerOlder