-
Notifications
You must be signed in to change notification settings - Fork 300
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
[Dart] Organize namespaces in Flutter bindings #2922
Comments
Hello @alfonsogarciacaro, However, it is true that having a similar experience as with native Futter/Dart can ease the usage. As you explaining, this is something that we did well with the About Did you try to use For example, in one of my binding I do something like that: // Binding code
namespace Feliz.Iconify
open Feliz
open Fable.Core
open Fable.Core.JsInterop
module Offline =
[<Erase>]
type Exports =
static member inline Icon (properties : #ISvgAttribute list) =
Interop.reactApi.createElement(import "Icon" "@iconify/react/dist/offline", createObj !!properties)
// Consumer code
open type Feliz.Iconify.Offline.Exports
Icon [ ] // Here I can directly access `Icon` because it is available now This allow me to have a close to 1-1 match compared to JavaScript API: import { Icon } from '@iconify/react/dist/offline';
<Icon /> |
I like how the Maybe we will get some wrappers to make the framework more F# and less like Dart, so perhaps those top-level functions will be a good fit for the first one. |
I was a bit worried that users had to call |
Oh 😲 I didn't know that |
This is about bindings for Flutter when targeting Dart, it could about bindings in general with Snake Island but each language/API has some peculiarities so let's focus on Flutter for now.
I assume Flutter will be the bindings most used for Fable>Dart users. I compare it to the Fable.Browser bindings but they will be used even more often because with React you don't need to access native Browser APIs that often.
To recap, with Fable.Browser bindings we decided:
Browser.Types
namespaceBrowser.Dom
) but with AutoOpen, so users would have access to all values of all referenced packages just withopen Browser
The decision to use
Browser.Types
was done because many times you don't need to access directly the types in Browser APIs. And also because we had problems previously withFable.Core.JS
namespace which contains anOption
interface. Because of this, when users openedFable.Core.JS
the F#Option
module got obscured and we wanted to prevent that (at the time F# could open two modules with the same name at the same time, but not a module and a class/interface, this seems to be solved now).Bindings in Dart are quite similar to JS with a few differences.
Import
attributes and helpers work the same in Dart as with JS (exceptImportDefault
)package:flutter/services.dart
)Rigth now, I'm having a single file for each Flutter module: https://github.com/alfonsogarciacaro/fable-flutterapp/tree/8128ae867b0c8d9761434536049fee299beeb3c9/src/Fable.Flutter
Probably we should add
AutoOpen
to most of the modules as it gets tedious to open all of them, except a couple of specific ones like Material and Cupertino. So users only need toopen Flutter
. Note that Dart itself does something similar by re-exporting most of the exports, so you only need to import the last module (like material).What I'm not sure about is what to do with the functions. For now I'm just adding adding a static class with the same name as the module so users call it like this:
The problem with this is when checking Flutter samples, users will have a hard time to identify where the functions come from so they don't know they have to qualify
showDialog
with Material andrunApp
with Widgets. Right now I can think of two solutions for this.Flutter
static class and add all functions to it as extensions. It will be similar to theAutoOpen
solution for type modules, but we probably also need to exclude Material and Cupertino modules, and I assume it will be more difficult to automate this solution.runApp
both from Material and Widgets (but notshowDialog
from Widgets), just as it happens in Dart.Thoughts? @Nhowka @MangelMaxime
The text was updated successfully, but these errors were encountered: