Skip to content

Instantly share code, notes, and snippets.

@alfonsogarciacaro
Created September 18, 2021 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfonsogarciacaro/f4c13eee4c5a98782c5ebcbd022aa1fe to your computer and use it in GitHub Desktop.
Save alfonsogarciacaro/f4c13eee4c5a98782c5ebcbd022aa1fe to your computer and use it in GitHub Desktop.
Fable decorators for Flask
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