Skip to content

Commit 356bb2f

Browse files
committed
v.4.0.3
* update model dirty flag for custom getters that depend on updated key (regression bug fixed for text livebind) * update examples
1 parent b4eed9c commit 356bb2f

9 files changed

Lines changed: 134 additions & 47 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It knows **where**, **when** and **what** needs to be rendered.
99

1010
![ModelView](/modelview.jpg)
1111

12-
**Version 4.0.2** (84 kB minified)
12+
**Version 4.0.3** (84 kB minified)
1313

1414

1515
**see also:**

beeld.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ tasks =[{}]
4141
replace =[{}]
4242
"@@ROOT@@" = "'undefined' !== typeof self ? self : this"
4343
"@@MODULE@@" = "ModelView"
44-
"@@VERSION@@" = "4.0.2"
44+
"@@VERSION@@" = "4.0.3"
4545
"@@DATE@@" = Xpresion::date("Y-m-d H:i:s")
4646
@
4747

build/modelview.bundle.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/modelview.js

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
*
33
* ModelView.js
4-
* @version: 4.0.2
5-
* @built on 2022-02-22 11:13:41
4+
* @version: 4.0.3
5+
* @built on 2022-03-03 09:50:25
66
*
77
* A simple, light-weight, versatile and fast MVVM framework
88
* optionaly integrates into both jQuery as MVVM plugin and jQueryUI as MVC widget
@@ -24,8 +24,8 @@ else if ( !(name in root) ) /* Browser/WebWorker/.. */
2424
/**
2525
*
2626
* ModelView.js
27-
* @version: 4.0.2
28-
* @built on 2022-02-22 11:13:41
27+
* @version: 4.0.3
28+
* @built on 2022-03-03 09:50:25
2929
*
3030
* A simple, light-weight, versatile and fast MVVM framework
3131
* optionaly integrates into both jQuery as MVVM plugin and jQueryUI as MVC widget
@@ -40,7 +40,7 @@ var HASDOC = ('undefined' !== typeof window) && ('undefined' !== typeof document
4040
/**[DOC_MARKDOWN]
4141
### ModelView API
4242
43-
**Version 4.0.2**
43+
**Version 4.0.3**
4444
4545
### Contents
4646
@@ -4960,7 +4960,7 @@ model.getVal( String dottedKey [, Boolean RAW=false ] );
49604960
if (0 > dottedKey.indexOf('.'))
49614961
{
49624962
// handle single key fast
4963-
if (!RAW && (r=getters[dottedKey]||getters[WILDCARD]) && r.v) return Value(r.v.call(model, dottedKey), dottedKey, true);
4963+
if (!RAW && (r=getters[dottedKey]||getters[WILDCARD]) && r.v) return Value(r.v.call(model, dottedKey), dottedKey, model.isDirty([dottedKey]));
49644964
return is_instance(data[dottedKey], Value) ? data[dottedKey] : Value(data[dottedKey], dottedKey, model.isDirty([dottedKey]));
49654965
}
49664966
else if ((r = walk_and_get2( ks=dottedKey.split('.'), data, RAW ? null : getters, Model )))
@@ -4974,7 +4974,7 @@ model.getVal( String dottedKey [, Boolean RAW=false ] );
49744974
else if (false === r[ 0 ])
49754975
{
49764976
ret = r[ 1 ].call(model, dottedKey);
4977-
return is_instance(ret, Value) ? ret : Value(ret, dottedKey, true);
4977+
return is_instance(ret, Value) ? ret : Value(ret, dottedKey, model.isDirty(ks));
49784978
}
49794979
// model field
49804980
return is_instance(r[ 1 ], Value) ? r[ 1 ] : Value(r[ 1 ], dottedKey, model.isDirty(ks));
@@ -5203,7 +5203,11 @@ model.set( String dottedKey, * val [, Boolean publish=false] );
52035203
model.setDirty(ks);
52045204

52055205
// notify any dependencies as well
5206-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
5206+
if (HAS.call(ideps,dottedKey))
5207+
{
5208+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
5209+
model.notify(ideps[dottedKey]);
5210+
}
52075211
}
52085212
return model;
52095213
}
@@ -5287,7 +5291,11 @@ model.set( String dottedKey, * val [, Boolean publish=false] );
52875291
});
52885292
model.setDirty(ks);
52895293
// notify any dependencies as well
5290-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
5294+
if (HAS.call(ideps,dottedKey))
5295+
{
5296+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
5297+
model.notify(ideps[dottedKey]);
5298+
}
52915299
}
52925300
if ( model.$atom && dottedKey === model.$atom ) model.atomic = true;
52935301
}
@@ -5320,7 +5328,11 @@ model.set( String dottedKey, * val [, Boolean publish=false] );
53205328
});
53215329
model.setDirty(ks);
53225330
// notify any dependencies as well
5323-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
5331+
if (HAS.call(ideps,dottedKey))
5332+
{
5333+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
5334+
model.notify(ideps[dottedKey]);
5335+
}
53245336
}
53255337

53265338
if (model.$atom && dottedKey === model.$atom) model.atomic = true;
@@ -5407,7 +5419,11 @@ model.[add|append]( String dottedKey, * val [, Boolean prepend=False, Boolean pu
54075419
});
54085420
model.setDirty(ks.concat(index));
54095421
// notify any dependencies as well
5410-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
5422+
if (HAS.call(ideps,dottedKey))
5423+
{
5424+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
5425+
model.notify(ideps[dottedKey]);
5426+
}
54115427
}
54125428
return model;
54135429
}
@@ -5496,7 +5512,11 @@ model.[add|append]( String dottedKey, * val [, Boolean prepend=False, Boolean pu
54965512
});
54975513
model.setDirty(ks);
54985514
// notify any dependencies as well
5499-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
5515+
if (HAS.call(ideps,dottedKey))
5516+
{
5517+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
5518+
model.notify(ideps[dottedKey]);
5519+
}
55005520
}
55015521
if (model.$atom && dottedKey === model.$atom) model.atomic = true;
55025522
}
@@ -5540,7 +5560,11 @@ model.[add|append]( String dottedKey, * val [, Boolean prepend=False, Boolean pu
55405560
});
55415561
model.setDirty(ks.concat(index));
55425562
// notify any dependencies as well
5543-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
5563+
if (HAS.call(ideps,dottedKey))
5564+
{
5565+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
5566+
model.notify(ideps[dottedKey]);
5567+
}
55445568
}
55455569
if (model.$atom && dottedKey === model.$atom) model.atomic = true;
55465570
}
@@ -5625,7 +5649,11 @@ model.[ins|insert]( String dottedKey, * val, Number index [, Boolean publish=fal
56255649
});
56265650
model.setDirty(ks.concat(index));
56275651
// notify any dependencies as well
5628-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
5652+
if (HAS.call(ideps,dottedKey))
5653+
{
5654+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
5655+
model.notify(ideps[dottedKey]);
5656+
}
56295657
}
56305658
return model;
56315659
}
@@ -5711,7 +5739,11 @@ model.[ins|insert]( String dottedKey, * val, Number index [, Boolean publish=fal
57115739
});
57125740
model.setDirty(ks.concat(index));
57135741
// notify any dependencies as well
5714-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
5742+
if (HAS.call(ideps,dottedKey))
5743+
{
5744+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
5745+
model.notify(ideps[dottedKey]);
5746+
}
57155747
}
57165748
if (model.$atom && dottedKey === model.$atom) model.atomic = true;
57175749
}
@@ -5745,7 +5777,11 @@ model.[ins|insert]( String dottedKey, * val, Number index [, Boolean publish=fal
57455777
});
57465778
model.setDirty(ks.concat(index));
57475779
// notify any dependencies as well
5748-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
5780+
if (HAS.call(ideps,dottedKey))
5781+
{
5782+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
5783+
model.notify(ideps[dottedKey]);
5784+
}
57495785
}
57505786
if (model.$atom && dottedKey === model.$atom) model.atomic = true;
57515787
}
@@ -8395,7 +8431,7 @@ console.log(viewText.render());
83958431
// export it
83968432
var ModelView = {
83978433

8398-
VERSION: "4.0.2"
8434+
VERSION: "4.0.3"
83998435

84008436
,UUID: uuid
84018437

build/modelview.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/hello-world-text-only.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h1>ModelView.js Hello Earth! (Text-only Binding)</h1>
2626
<b>Hello {msg}</b> &nbsp;&nbsp;(updated live on <i>keyup</i>)
2727
<br /><br />
2828
<input type="text" name="model[msg]" size="50" value="" mv-evt mv-on-keyup="update" />
29-
<button class="button" title="{msg}" mv-evt mv-on-click="alert">Hello</button>
29+
<button class="button" title="{msg.hello}" mv-evt mv-on-click="alert">{hello}</button>
3030
<button class="button" mv-evt mv-on-click="hello_world">Hello World</button>
3131
</script>
3232
<div id="app"></div>
@@ -44,6 +44,17 @@ <h1>ModelView.js Hello Earth! (Text-only Binding)</h1>
4444
// model data here ..
4545
{msg: 'Earth!'}
4646
)
47+
.getters({
48+
hello: function(){
49+
return 'Hello ' + this.$data.msg;
50+
},
51+
'msg.hello': function(){
52+
return 'Say "Hello ' + this.$data.msg + '"';
53+
}
54+
})
55+
.dependencies({
56+
"hello": ["msg"]
57+
})
4758
// model data type-casters (if any) here ..
4859
.types({msg: ModelView.Type.Cast.STR})
4960
// model data validators (if any) here ..

examples/todomvc.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,23 @@ function updateModelFromStorage()
7676

7777
function timeSince(time)
7878
{
79-
var seconds = Math.floor((new Date().getTime() - time) / 1000), interval;
79+
var seconds = Math.floor((new Date().getTime() - time) / 1000),
80+
then = 0 > seconds ? " later" : " ago",
81+
now = 0 > seconds ? "about now" : "just now",
82+
interval;
83+
seconds = Math.abs(seconds);
8084
interval = Math.floor(seconds / 31536000);
81-
if (interval > 0) return String(interval) + " "+(1===interval?'year':'years')+" ago";
85+
if (interval > 0) return String(interval) + " " + (1===interval?'year':'years') + then;
8286
interval = Math.floor(seconds / 2592000);
83-
if (interval > 0) return String(interval) + " "+(1===interval?'month':'months')+" ago";
87+
if (interval > 0) return String(interval) + " " + (1===interval?'month':'months') + then;
8488
interval = Math.floor(seconds / 86400);
85-
if (interval > 0) return String(interval) + " "+(1===interval?'day':'days')+" ago";
89+
if (interval > 0) return String(interval) + " " + (1===interval?'day':'days') + then;
8690
interval = Math.floor(seconds / 3600);
87-
if (interval > 0) return String(interval) + " "+(1===interval?'hour':'hours')+" ago";
91+
if (interval > 0) return String(interval) + " " + (1===interval?'hour':'hours') + then;
8892
interval = Math.floor(seconds / 60);
89-
if (interval > 0) return String(interval) + " "+(1===interval?'minute':'minutes')+" ago";
93+
if (interval > 0) return String(interval) + " " + (1===interval?'minute':'minutes') + then;
9094
interval = Math.floor(seconds);
91-
return interval < 30 ? "just now" : String(interval) + " seconds ago";
95+
return interval < 30 ? now : String(interval) + " seconds" + then;
9296
}
9397

9498
function route(displayMode)

manual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
### ModelView API
33

4-
**Version 4.0.2**
4+
**Version 4.0.3**
55

66
### Contents
77

src/model.js

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ model.getVal( String dottedKey [, Boolean RAW=false ] );
943943
if (0 > dottedKey.indexOf('.'))
944944
{
945945
// handle single key fast
946-
if (!RAW && (r=getters[dottedKey]||getters[WILDCARD]) && r.v) return Value(r.v.call(model, dottedKey), dottedKey, true);
946+
if (!RAW && (r=getters[dottedKey]||getters[WILDCARD]) && r.v) return Value(r.v.call(model, dottedKey), dottedKey, model.isDirty([dottedKey]));
947947
return is_instance(data[dottedKey], Value) ? data[dottedKey] : Value(data[dottedKey], dottedKey, model.isDirty([dottedKey]));
948948
}
949949
else if ((r = walk_and_get2( ks=dottedKey.split('.'), data, RAW ? null : getters, Model )))
@@ -957,7 +957,7 @@ model.getVal( String dottedKey [, Boolean RAW=false ] );
957957
else if (false === r[ 0 ])
958958
{
959959
ret = r[ 1 ].call(model, dottedKey);
960-
return is_instance(ret, Value) ? ret : Value(ret, dottedKey, true);
960+
return is_instance(ret, Value) ? ret : Value(ret, dottedKey, model.isDirty(ks));
961961
}
962962
// model field
963963
return is_instance(r[ 1 ], Value) ? r[ 1 ] : Value(r[ 1 ], dottedKey, model.isDirty(ks));
@@ -1186,7 +1186,11 @@ model.set( String dottedKey, * val [, Boolean publish=false] );
11861186
model.setDirty(ks);
11871187

11881188
// notify any dependencies as well
1189-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
1189+
if (HAS.call(ideps,dottedKey))
1190+
{
1191+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
1192+
model.notify(ideps[dottedKey]);
1193+
}
11901194
}
11911195
return model;
11921196
}
@@ -1270,7 +1274,11 @@ model.set( String dottedKey, * val [, Boolean publish=false] );
12701274
});
12711275
model.setDirty(ks);
12721276
// notify any dependencies as well
1273-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
1277+
if (HAS.call(ideps,dottedKey))
1278+
{
1279+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
1280+
model.notify(ideps[dottedKey]);
1281+
}
12741282
}
12751283
if ( model.$atom && dottedKey === model.$atom ) model.atomic = true;
12761284
}
@@ -1303,7 +1311,11 @@ model.set( String dottedKey, * val [, Boolean publish=false] );
13031311
});
13041312
model.setDirty(ks);
13051313
// notify any dependencies as well
1306-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
1314+
if (HAS.call(ideps,dottedKey))
1315+
{
1316+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
1317+
model.notify(ideps[dottedKey]);
1318+
}
13071319
}
13081320

13091321
if (model.$atom && dottedKey === model.$atom) model.atomic = true;
@@ -1390,7 +1402,11 @@ model.[add|append]( String dottedKey, * val [, Boolean prepend=False, Boolean pu
13901402
});
13911403
model.setDirty(ks.concat(index));
13921404
// notify any dependencies as well
1393-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
1405+
if (HAS.call(ideps,dottedKey))
1406+
{
1407+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
1408+
model.notify(ideps[dottedKey]);
1409+
}
13941410
}
13951411
return model;
13961412
}
@@ -1479,7 +1495,11 @@ model.[add|append]( String dottedKey, * val [, Boolean prepend=False, Boolean pu
14791495
});
14801496
model.setDirty(ks);
14811497
// notify any dependencies as well
1482-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
1498+
if (HAS.call(ideps,dottedKey))
1499+
{
1500+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
1501+
model.notify(ideps[dottedKey]);
1502+
}
14831503
}
14841504
if (model.$atom && dottedKey === model.$atom) model.atomic = true;
14851505
}
@@ -1523,7 +1543,11 @@ model.[add|append]( String dottedKey, * val [, Boolean prepend=False, Boolean pu
15231543
});
15241544
model.setDirty(ks.concat(index));
15251545
// notify any dependencies as well
1526-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
1546+
if (HAS.call(ideps,dottedKey))
1547+
{
1548+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
1549+
model.notify(ideps[dottedKey]);
1550+
}
15271551
}
15281552
if (model.$atom && dottedKey === model.$atom) model.atomic = true;
15291553
}
@@ -1608,7 +1632,11 @@ model.[ins|insert]( String dottedKey, * val, Number index [, Boolean publish=fal
16081632
});
16091633
model.setDirty(ks.concat(index));
16101634
// notify any dependencies as well
1611-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
1635+
if (HAS.call(ideps,dottedKey))
1636+
{
1637+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
1638+
model.notify(ideps[dottedKey]);
1639+
}
16121640
}
16131641
return model;
16141642
}
@@ -1694,7 +1722,11 @@ model.[ins|insert]( String dottedKey, * val, Number index [, Boolean publish=fal
16941722
});
16951723
model.setDirty(ks.concat(index));
16961724
// notify any dependencies as well
1697-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
1725+
if (HAS.call(ideps,dottedKey))
1726+
{
1727+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
1728+
model.notify(ideps[dottedKey]);
1729+
}
16981730
}
16991731
if (model.$atom && dottedKey === model.$atom) model.atomic = true;
17001732
}
@@ -1728,7 +1760,11 @@ model.[ins|insert]( String dottedKey, * val, Number index [, Boolean publish=fal
17281760
});
17291761
model.setDirty(ks.concat(index));
17301762
// notify any dependencies as well
1731-
if (HAS.call(ideps,dottedKey)) model.notify(ideps[dottedKey]);
1763+
if (HAS.call(ideps,dottedKey))
1764+
{
1765+
ideps[dottedKey].forEach(function(kk){model.setDirty(kk.split('.'));});
1766+
model.notify(ideps[dottedKey]);
1767+
}
17321768
}
17331769
if (model.$atom && dottedKey === model.$atom) model.atomic = true;
17341770
}

0 commit comments

Comments
 (0)