From f803da2008fad350e41098b3953a0183d9678420 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Thu, 21 Aug 2014 12:53:37 -0400 Subject: [PATCH] fix custom getter setter example --- archive/v0.1.21/getting-started.html | 10 ++++++++-- archive/v0.1.21/mithril.min.zip | Bin 65836 -> 65836 bytes 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/archive/v0.1.21/getting-started.html b/archive/v0.1.21/getting-started.html index 8278fb28..c90962e8 100644 --- a/archive/v0.1.21/getting-started.html +++ b/archive/v0.1.21/getting-started.html @@ -362,13 +362,19 @@ m.module(document, todo);
this.description = m.prop(data.description)

becomes:

//private store
-var description = data.description;
+var description;
 
 //public getter-setter
 this.description = function(value) {
     if (arguments.length > 0) description = value.toUpperCase();
     return description;
-}
+} + +//make it serializable +this.description.toJSON = function() {return description} + +//set the value +this.description(data.description)

According to Mithril's philosophy, list and description are also considered model-level entities. This is a subtle but important point: model entities don't need to be full-blown custom classes.

Native Javascript classes are quite appropriate for storing primitive and structured data. Since in this case they are indeed being used to store data - even if temporarily - they are model entities!

Be aware that by using the native Array class for a list, we're making an implicit statement that we are going to support all of the standard Array methods as part of our API.

diff --git a/archive/v0.1.21/mithril.min.zip b/archive/v0.1.21/mithril.min.zip index 1ed472c8c0271cf5655a3a83ca46cd581549511a..9b99d2eec557707a460226cbda8ff4811cea7bca 100644 GIT binary patch delta 66 zcmZ3}#ImM|g*U*PnT3l11Qw);ZsfgW!VIK0KQhS)0y6^J6)HiDsU?h-V0r_i6_|d@ GXb%95{uILi delta 66 zcmZ3}#ImM|g*U*PnT3l11XfHF*~ojzgc(S0eq@pp1ZD)bD^!9QQ%e{v!Sn`3D=__* G(H;P>%N7j)