Skip to content

Commit 1e02fba

Browse files
committed
v.5.0.1
* component updated lifecycle hook supported
1 parent 230fef8 commit 1e02fba

8 files changed

Lines changed: 49 additions & 27 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 5.0.0** (93 kB minified, 29 kB gzipped)
12+
**Version 5.0.1** (93 kB minified, 29 kB gzipped)
1313

1414

1515
**see also:**

beeld.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tasks =[{}]
3636
header = ./src/header.js
3737

3838
replace =[{}]
39-
"@@VERSION@@" = "5.0.0"
39+
"@@VERSION@@" = "5.0.1"
4040
"@@DATE@@" = Xpresion::date("Y-m-d H:i:s")
4141
@
4242

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: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
*
33
* ModelView.js
4-
* @version: 5.0.0
5-
* @built on 2022-03-30 11:03:44
4+
* @version: 5.0.1
5+
* @built on 2022-04-09 14:29:23
66
*
77
* A simple, light-weight, versatile and fast isomorphic MVVM JavaScript framework (Browser and Server)
88
* https://github.com/foo123/modelview.js
99
*
1010
**//**
1111
*
1212
* ModelView.js
13-
* @version: 5.0.0
14-
* @built on 2022-03-30 11:03:44
13+
* @version: 5.0.1
14+
* @built on 2022-04-09 14:29:23
1515
*
1616
* A simple, light-weight, versatile and fast isomorphic MVVM JavaScript framework (Browser and Server)
1717
* https://github.com/foo123/modelview.js
@@ -36,7 +36,7 @@ var HASDOC = ('undefined' !== typeof window) && ('undefined' !== typeof document
3636
/**[DOC_MARKDOWN]
3737
### ModelView API
3838
39-
**Version 5.0.0**
39+
**Version 5.0.1**
4040
4141
### Contents
4242
@@ -7663,9 +7663,9 @@ function clearInvalid(view)
76637663
if (is_instance(comp, MVComponentInstance))
76647664
{
76657665
COMP = view.$components['#'+comp.name];
7666-
if (2 === comp.status || !is_child_of(comp.dom, view.$renderdom, view.$renderdom))
7666+
if ((2 === comp.status) || !is_child_of(comp.dom, view.$renderdom, view.$renderdom))
76677667
{
7668-
if (1 === comp.status)
7668+
if (1 === comp.status || 10 === comp.status)
76697669
{
76707670
comp.status = 2;
76717671
if (comp.dom && COMP && COMP.opts && 'function' === typeof COMP.opts.detached)
@@ -7683,6 +7683,12 @@ function clearInvalid(view)
76837683
if (comp.dom && COMP && COMP.opts && 'function' === typeof COMP.opts.attached)
76847684
COMP.opts.attached.call(comp, comp);
76857685
}
7686+
else if (10 === comp.status)
7687+
{
7688+
comp.status = 1;
7689+
if (comp.dom && COMP && COMP.opts && 'function' === typeof COMP.opts.updated)
7690+
COMP.opts.updated.call(comp, comp);
7691+
}
76867692
}
76877693
}
76887694
});
@@ -8116,6 +8122,9 @@ view.components( Object components );
81168122
out.component = component;
81178123
out.changed = changed;
81188124
out.simple = false; // components are not simple nodes
8125+
// set component.status to updated
8126+
if (changed && (1 === component.status)) component.status = 10;
8127+
else if (!changed && (10 === component.status)) component.status = 1;
81198128
return out;
81208129
}
81218130
}
@@ -9148,8 +9157,9 @@ var MyComponent = ModelView.View.Component(
91489157
String name,
91499158
String htmlTpl [,
91509159
Object options = {
9151-
attached: (componentInstance) => {} // component attached to DOM, for componentInstance see below
9152-
,detached: (componentInstance) => {} // component detached from DOM, for componentInstance see below
9160+
attached: (componentInstance) => {} // component has been attached to DOM, for componentInstance see below
9161+
,updated: (componentInstance) => {} // component has been updated, for componentInstance see below
9162+
,detached: (componentInstance) => {} // component has been detached from DOM, for componentInstance see below
91539163
,changed: (oldData, newData, componentInstance) => false // whether component has changed given new data
91549164
,model: () => ({clicks:0}) // initial state model data, if state model is to be used, else null
91559165
,actions: {
@@ -9342,7 +9352,7 @@ console.log(viewText.render());
93429352
// export it
93439353
var ModelView = {
93449354

9345-
VERSION: "5.0.0"
9355+
VERSION: "5.0.1"
93469356

93479357
,UUID: uuid
93489358

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.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ <h1>ModelView.js Hello Earth!</h1>
7272
},
7373
changed: (oldData, newData) => false,
7474
attached: (comp) => {console.log('HelloButton attached to DOM <'+comp.dom.tagName+'>')},
75+
updated: (comp) => {console.log('HelloButton updated with '+comp.model.get('clicks')+' clicks')},
7576
detached: (comp) => {console.log('HelloButton detached from DOM <'+comp.dom.tagName+'>')}
7677
}
7778
),

manual.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
### ModelView API
33

4-
**Version 5.0.0**
4+
**Version 5.0.1**
55

66
### Contents
77

@@ -836,8 +836,9 @@ var MyComponent = ModelView.View.Component(
836836
String name,
837837
String htmlTpl [,
838838
Object options = {
839-
attached: (componentInstance) => {} // component attached to DOM, for componentInstance see below
840-
,detached: (componentInstance) => {} // component detached from DOM, for componentInstance see below
839+
attached: (componentInstance) => {} // component has been attached to DOM, for componentInstance see below
840+
,updated: (componentInstance) => {} // component has been updated, for componentInstance see below
841+
,detached: (componentInstance) => {} // component has been detached from DOM, for componentInstance see below
841842
,changed: (oldData, newData, componentInstance) => false // whether component has changed given new data
842843
,model: () => ({clicks:0}) // initial state model data, if state model is to be used, else null
843844
,actions: {

src/view.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,9 @@ function clearInvalid(view)
499499
if (is_instance(comp, MVComponentInstance))
500500
{
501501
COMP = view.$components['#'+comp.name];
502-
if (2 === comp.status || !is_child_of(comp.dom, view.$renderdom, view.$renderdom))
502+
if ((2 === comp.status) || !is_child_of(comp.dom, view.$renderdom, view.$renderdom))
503503
{
504-
if (1 === comp.status)
504+
if (1 === comp.status || 10 === comp.status)
505505
{
506506
comp.status = 2;
507507
if (comp.dom && COMP && COMP.opts && 'function' === typeof COMP.opts.detached)
@@ -519,6 +519,12 @@ function clearInvalid(view)
519519
if (comp.dom && COMP && COMP.opts && 'function' === typeof COMP.opts.attached)
520520
COMP.opts.attached.call(comp, comp);
521521
}
522+
else if (10 === comp.status)
523+
{
524+
comp.status = 1;
525+
if (comp.dom && COMP && COMP.opts && 'function' === typeof COMP.opts.updated)
526+
COMP.opts.updated.call(comp, comp);
527+
}
522528
}
523529
}
524530
});
@@ -952,6 +958,9 @@ view.components( Object components );
952958
out.component = component;
953959
out.changed = changed;
954960
out.simple = false; // components are not simple nodes
961+
// set component.status to updated
962+
if (changed && (1 === component.status)) component.status = 10;
963+
else if (!changed && (10 === component.status)) component.status = 1;
955964
return out;
956965
}
957966
}
@@ -1984,8 +1993,9 @@ var MyComponent = ModelView.View.Component(
19841993
String name,
19851994
String htmlTpl [,
19861995
Object options = {
1987-
attached: (componentInstance) => {} // component attached to DOM, for componentInstance see below
1988-
,detached: (componentInstance) => {} // component detached from DOM, for componentInstance see below
1996+
attached: (componentInstance) => {} // component has been attached to DOM, for componentInstance see below
1997+
,updated: (componentInstance) => {} // component has been updated, for componentInstance see below
1998+
,detached: (componentInstance) => {} // component has been detached from DOM, for componentInstance see below
19891999
,changed: (oldData, newData, componentInstance) => false // whether component has changed given new data
19902000
,model: () => ({clicks:0}) // initial state model data, if state model is to be used, else null
19912001
,actions: {

0 commit comments

Comments
 (0)