Omnitalented

Converting My Contacts: Step 4. Finishing it up

September 23, 2020

This article is a part of a series on converting My Contacts app using Laconic. The start of the series is here.

Step 4: Completing the Migration

The final screen we migrated is Contact Details:



Bindings for Xamarin.Forms.Maps are provided by a separate project inside the Laconic’s repository.

All MVU, No MVVM

With the migration complete we removed all XAML, all vestiges of MVVM. No more type converters, no more markup extensions. No more DI, no more commands, no more data binding. Good stuff, but rather than explaining here the difference and advantages of MVU vs MVVM may I ask you to read this excellent article by Timothé Larivière on Xamarin’s blog?

Laconic is built on the same principles as Fabulous, although the terminology is different. As with Fabulous, our app has an immutable state, and a pure function for updating it, called MainReducer. The reducer takes the current state and a signal, which is the Laconic’s name for messages, and returns the updated state.

Like in Fabulous this new state is passed to pure functions that calculate virtual views called blueprints. Blueprints are unambiguous definitions of how the app views must appear given the current state. Laconic’s diff/patch mechanism then decides which properties of actual Xamarin.Forms views should be updated.

3rd Party Controls

The updated code gives an example of how to bring third party controls into the Laconic’s diff/patch cycle. The original codebase used PancakeView, and to make it work we wrote a small binding class.

Middleware

Our app makes calls to file system (or network), queries device sensors, must react to device theme changes. These interactions are not pure by definition. We put all impure code in middleware, neatly wired in one place in the App’s constructor.

Final Stats

Original codebase:

------------------------------------------------------------------
Language        files          blank        comment           code
------------------------------------------------------------------
C#                 51            435            250           1952
XAML                9            103             19            922
MSBuild script      6             13              7            597
XML                12             20             32            476
JSON                4              0              0            157
Bourne Shell        3              6              2             17
------------------------------------------------------------------
SUM:               85            577            310           4121
------------------------------------------------------------------

Character count, XAML and C# files: 130,047

Full Laconic codebase:

------------------------------------------------------------------
Language        files          blank        comment           code
------------------------------------------------------------------
C#                 30            283            155           1680
MSBuild script      6             11              7            574
XML                12             20             32            476
JSON                4              0              0            157
XAML                2              3              0             19
Bourne Shell        3              6              2             17
------------------------------------------------------------------
SUM:               58            346            196           2961
------------------------------------------------------------------

(Remaining XAML is in UWP project which wasn’t touched)

Character count, XAML and C# files: 82,240

I’d say this is quite a reduction in size… But more importantly, the resulting code is easier to understand and maintain.

Here is the commit for this step.