Skip to content
💅 Extensions to make MvvmCross bindings more F#-ish
F# Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.paket 🔧 Add FAKE Jul 30, 2017
MvvmCross.FSharp.Droid 📦 Update packages Sep 17, 2017
MvvmCross.FSharp.iOS 📦 Update packages Sep 17, 2017
MvvmCross.FSharp Add support to byCombining Sep 17, 2017
.gitignore 🔧 Add FAKE Jul 30, 2017
MvvmCross.FSharp.nuspec
MvvmCross.FSharp.sln :shipit: Bump version Aug 27, 2017
README.md 📝 Update docs Aug 27, 2017
build.fsx 📦 Update build script Aug 27, 2017
build.sh 🔧 Add FAKE Jul 30, 2017
paket.dependencies Generate typed default property bindings Aug 19, 2017
paket.lock Generate typed default property bindings Aug 19, 2017
scrape.fsx Generate typed default property bindings Aug 19, 2017

README.md

MvvmCross.FSharp

💅 Extensions to make MvvmCross bindings more F#-ish

Installation

Install via NuGet using:

PM> Install-Package MvvmCross.FSharp

wat?

This is what bindings in F# look like:

let set = this.CreateBindingSet<MyView, MyViewModel>()

set
  .Bind(source)
  .To("MyList") 
  |> ignore

set
  .Bind(source)
  .For("SelectionChangedCommand")
  .To("MyCommand") 
  |> ignore
  
set.Apply()

MvvmCross.FSharp® allows you to use quotations instead of strings for additional type safety:

let set = this.CreateBindingSet<MyView, MyViewModel>()

set
|> bind source
|> toExpression <@ this.ViewModel.MyList @>
|> ignore

set
|> bind source
|> forExpression <@ source.SelectionChangedCommand @>
|> toExpression <@ this.ViewModel.MyCommand @>
|> ignore

apply set

<| ALSO PIPES |>

DSL

You can also use a DSL based on the operators:

  • |>>: The bind operator
  • >>: The to operator
  • >>>>: The for operator

Note that >> = to = TWO characters. The same applies to the for operator. Mnemonics FTW.

To use plain text instead of quotations when using the custom operators, replace the last > with a .. The number of characters in the operator remains the same, so it's still easy to remember.

Here's what the sample bindings would look like using the operator DSL:

let set = this.CreateBindingSet<MyView, MyViewModel>()
set |>> source >> <@ this.ViewModel.MyList @> |> ignore
set |>> source >>>> <@ source.SelectionChangedCommand @> >> <@ this.ViewModel.MyCommand @> |> ignore
apply set

Framework provided bindings

A script scrapes the MvvmCross source code and generates a source file that provides type safe for methods for each of the default-framework-provided bindings. This allows you to use bindings that are provided by the framework in a type safe way, like this:

open MvvmCross.FSharp.iOS.PropertyBinding

set
|> bind myButton
|> forTouchDown
|> toExpression <@ this.ViewModel.MyCommand @> 
|> ignore

What's next?

  • Make the DSL even better®
  • Turn the scrape script into a Type Provider
You can’t perform that action at this time.