Created
September 18, 2021 12:27
-
-
Save alfonsogarciacaro/f4c13eee4c5a98782c5ebcbd022aa1fe to your computer and use it in GitHub Desktop.
Fable decorators for Flask
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
module Flask = | |
type App() = class end | |
[<AbstractClass>] | |
type RouteAttribute(route: string) = | |
inherit JS.DecoratorAttribute() | |
abstract App: App | |
override this.Decorate(fn) = | |
let app = this.App // Access the app | |
// Do some initialization | |
fn // Return the function | |
// User code | |
let app = Flask.App() // Initialize the app | |
// User overrides the attribute to give it access to the app | |
type RouteAttribute(route: string) = | |
inherit Flask.RouteAttribute(route) | |
override _.App = app | |
// Declare the routes | |
[<Route("/foo")>] | |
let foo() = () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment