Skip to content

Commit

Permalink
Added the _render method, fixed an issue on $append and added the met…
Browse files Browse the repository at this point in the history
…hod $listenOnce.
  • Loading branch information
jclo committed Jul 16, 2021
1 parent ee4f8cb commit 0967d1f
Show file tree
Hide file tree
Showing 17 changed files with 433 additions and 102 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
### HEAD
###

### 1.0.5 (March 9, 2021)

* Added the _render method to increase the robustness of $removeChild,
* Fixed an issue to prevent $append to fire twice the component method events for childs,
* Add The method $listenOnce,
* ...,


### 1.0.4 (February 18, 2021)

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ $getIdAndName() | returns the component's Id and name,
$hyperscript(args) | converts an hyperscript format to an XML string,
$setState() | updates a state value and updates the DOM accordingly,
$listen(event, handler) | listens a message,
$listenOnce(event, handler) | listens a message once,
$emit(event, payload) | sends a message,
```

Expand Down Expand Up @@ -493,7 +494,7 @@ $().remove() | removes the element from the DOM (to handle wi
[npm-url]: https://www.npmjs.com/package/@mobilabs/rview
[release-url]: https://github.com/jclo/rview/tags
[commit-url]: https://github.com/jclo/rview/commits/master
[travis-url]: https://travis-ci.org/jclo/rview
[travis-url]: https://travis-ci.com/jclo/rview
[coveralls-url]: https://coveralls.io/github/jclo/rview?branch=master
[dependencies-url]: https://david-dm.org/jclo/rview
[devdependencies-url]: https://david-dm.org/jclo/rview?type=dev
Expand Down
3 changes: 2 additions & 1 deletion _dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ $getIdAndName() | returns the component's Id and name,
$hyperscript(args) | converts an hyperscript format to an XML string,
$setState() | updates a state value and updates the DOM accordingly,
$listen(event, handler) | listens a message,
$listenOnce(event, handler) | listens a message once,
$emit(event, payload) | sends a message,
```

Expand Down Expand Up @@ -493,7 +494,7 @@ $().remove() | removes the element from the DOM (to handle wi
[npm-url]: https://www.npmjs.com/package/@mobilabs/rview
[release-url]: https://github.com/jclo/rview/tags
[commit-url]: https://github.com/jclo/rview/commits/master
[travis-url]: https://travis-ci.org/jclo/rview
[travis-url]: https://travis-ci.com/jclo/rview
[coveralls-url]: https://coveralls.io/github/jclo/rview?branch=master
[dependencies-url]: https://david-dm.org/jclo/rview
[devdependencies-url]: https://david-dm.org/jclo/rview?type=dev
Expand Down
72 changes: 54 additions & 18 deletions _dist/lib/rview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! ****************************************************************************
* RView v1.0.4
* RView v1.0.5
*
* A companion Reactive View library for building web applications.
* (you can download it from npm or github repositories)
Expand Down Expand Up @@ -119,7 +119,7 @@

// Useful to retrieve the library name and version when it is
// embedded in another library as an object:
_library: { name: 'RView', version: '1.0.4' },
_library: { name: 'RView', version: '1.0.5' },


// -- Private Static Methods ---------------------------------------------
Expand Down Expand Up @@ -272,7 +272,7 @@

// Attaches constants to RView that provide name and version of the lib.
RView.NAME = 'RView';
RView.VERSION = '1.0.4';
RView.VERSION = '1.0.5';


// -- Export
Expand Down Expand Up @@ -1723,6 +1723,7 @@
* Private Methods:
* . _init executes the private init when the comp. is created,
* . _renderer renders the component an its children, return XML,
* . _render returns data returned by the public method render,
*
*
* Public Variables:
Expand Down Expand Up @@ -1852,6 +1853,34 @@
return R.render(this);
},

/**
* Returns data returned by the public method render.
* (must not be overwritten)
*
* @method ([arg1], [arg2])
* @public
* @param {Object} the state properties,
* @param {Object} the optional properties,
* @returns {XMLString} returns the component's XMLString,
* @since 0.0.0
*/
_render(...args) {
/*
xml = xml.replace(/<!--(.*?)-->/g, '') // remove comments
.replace(/\n\s+</g, '\n<') // remove leading spaces before a tag,
.replace(/\n<\/div>/g, '</div>') // remove unwanted `\n`,
.replace(/\n<\/ul>/g, '</ul>') // -
.replace(/\n<\/li>/g, '</li>') // -
.replace(/\n<\/a>/g, '</a>') // -
;
*/
const xml = this.render(...args);
if (_.isString(xml)) {
return xml.trim();
}
return xml;
},


// -- Defined Public Methods ---------------------------------------------

Expand Down Expand Up @@ -2083,7 +2112,7 @@
* @method ()
* @public
* @param {} -,
* @returns {Object} returns this,
* @returns {String} returns XMLString,
* @since 0.0.0
*/
render() {
Expand Down Expand Up @@ -2906,7 +2935,7 @@
* can't be intantiated.
*
* Private Functions:
* . _fireEvents executes the component method events,
* . _fireEvents executes the child component method events,
* . _attachMess attaches the messenger to the child component,
* . _attachChild attaches a child to the passed-in component,
* . _insert inserts a child component,
Expand Down Expand Up @@ -2945,23 +2974,21 @@
// -- Private Functions ----------------------------------------------------

/**
* Executes the component method events.
* Executes the child component method events.
*
* @function (arg1)
* @private
* @param {Object} the component,
* @returns {} -,
* @since 0.0.0
*/
function _fireEvents(co) {
co.events();

function _fireChildEvents(co) {
// Processes recursively cList to fire child events.
if (co._cList) {
const keys = Object.keys(co._cList);
for (let i = 0; i < keys.length; i++) {
co._cList[keys[i]].events();
_fireEvents(co._cList[keys[i]]);
_fireChildEvents(co._cList[keys[i]]);
}
}
}
Expand Down Expand Up @@ -3039,7 +3066,9 @@
* @since 0.0.0
*/
function _insert(co, prepend, ...args) {
const [tag, child, opts] = args;
const [tag, child, options] = args
, opts = options || {}
;

// Links the child to the parent component.
_attachChild(co, prepend, tag, child, opts.state, opts.props);
Expand All @@ -3057,9 +3086,10 @@
// child component to the DOM.
co.$setState({});

// And finally, we have to run the 'events' methods to attach the DOM
// events to this child component.
_fireEvents(c);
// And finally, we have to run the 'events' method to attach the DOM
// events to this child component and its own childs if any.
c.events();
_fireChildEvents(c);
}


Expand Down Expand Up @@ -3268,7 +3298,7 @@
;

// Render the component and check if it is an hyperscript:
xml = co.render(co.state, co.props);
xml = co._render(co.state, co.props);
if (_.isLiteralObject(xml) && _.isString(xml.nodeName)) {
// This is an hyperscript object. We need to convert it to a serialized
// node:
Expand Down Expand Up @@ -3363,7 +3393,7 @@
* @since 0.0.0
*/
function _reRender(co) {
let xml = co.render(co.state, co.props);
let xml = co._render(co.state, co.props);
if (_.isLiteralObject(xml) && _.isString(xml.nodeName)) {
xml = Hyper.render(xml, {});
}
Expand Down Expand Up @@ -3665,8 +3695,8 @@
|| ident === co._cList[key].name) {
return { parent: co, child: co._cList[key] };
}
const child = _search(co._cList[key], ident);
if (child) return child;
const res = _search(co._cList[key], ident);
if (res.child) return res;
}
return { parent: co, child: null };
}
Expand Down Expand Up @@ -3705,6 +3735,12 @@
// 4. Remove all traces from parent:
delete r.parent._cList[stag];
delete r.parent.children[tag];
if (r.parent._append) {
r.parent._append = r.parent._append.filter((item) => item !== tag);
}
if (r.parent._prepend) {
r.parent._prepend = r.parent._prepend.filter((item) => item !== tag);
}

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions _dist/lib/rview.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _dist/lib/rview.min.mjs

Large diffs are not rendered by default.

Loading

0 comments on commit 0967d1f

Please sign in to comment.