Skip to content

Commit

Permalink
improved adaptComponent & implemented JSX support
Browse files Browse the repository at this point in the history
  • Loading branch information
LeXofLeviafan committed Jun 20, 2023
1 parent 4405389 commit e7ddfca
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Cakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[fs, {dirname}, {spawnSync}, CoffeeScript] = ['fs', 'path', 'child_process', 'coffeescript'].map require

modules = ['util', 'atom', 'reagent', 're-frame']
modules = ['util', 'atom', 'reagent', 're-frame', 'jsx-runtime']
deps = "mithril/mount,mithril/render,mithril/redraw,mithril/hyperscript"
depsRoute = "#{deps},mithril/route"

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ For further information, see [API reference](#api-reference) below and the follo
* Q: I have a _huge_ amount of DB events per second in my app, can I disable the deep-equality check in `db` effect handler?
A: Specify `eq` in [`rf._init`](docs/re-frame.md#_init-opts) to replace it with either [`eqShallow`](docs/util.md#eqShallow-a-b)
or [`indentical`](docs/util.md#identical-a-b).
* Q: I hate commas and languages that aren't syntactical supersets of JS. Can I still use this somehow?
A: Well if you _absolutely must_, you can [use JSX](docs/jsx-runtime.md). (Note that JSX is not exatly a great match for Reagent components.)


# Examples
Expand All @@ -161,6 +163,7 @@ For further information, see [API reference](#api-reference) below and the follo
* [Routing using `mithril/route` (from `mreframe-route.js`)](examples/route.js.html) (scripted in JavaScript)
[[live]](https://lexofleviafan.github.io/mreframe/examples/route.js.html)
* [Rendering HTML from Reagent components using `mithril-node-render`](examples/node-render.coffee) (scripted in CoffeeScript)
* [JSX usage example](examples/reagent.jsx)


# API reference
Expand All @@ -175,6 +178,8 @@ For further information, see [API reference](#api-reference) below and the follo
for Mithril;
* [`re-frame`](docs/re-frame.md) defines a system for managing state/side-effects in a Reagent/Mithril application.

There's also [`jsx-runtime`](docs/jsx-runtime.md) which isn't included in main module (it implements JSX support).

Each of these can be used separately (`require('mreframe/<name>')`), or as part of the main module
(`require('mreframe').<name>`; `.reFrame` in case of `re-frame` module). Note that the nodeps bundle doesn't load
Mithril libraries by default (so you'll have to call the `_init` function which it also exports).
Expand Down
34 changes: 27 additions & 7 deletions dist/mreframe-nodeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,25 @@ require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=

}).call(this);

},{"./util":"mreframe/util"}],"mreframe/re-frame":[function(require,module,exports){
},{"./util":"mreframe/util"}],"mreframe/jsx-runtime":[function(require,module,exports){
(function() {
var jsx, r;

r = require('./reagent');

jsx = (tag, {children = [], ...attrs}, key) => { // this API isn't documented properly...
return r.with({key, ...attrs}, [tag].concat(children));
};

module.exports = {
jsx,
jsxs: jsx,
Fragment: '<>'
};

}).call(this);

},{"./reagent":"mreframe/reagent"}],"mreframe/re-frame":[function(require,module,exports){
(function() {

/*
Expand Down Expand Up @@ -542,7 +560,7 @@ require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=

},{"./atom":"mreframe/atom","./reagent":"mreframe/reagent","./util":"mreframe/util"}],"mreframe/reagent":[function(require,module,exports){
(function() {
var RAtom, RCursor, _createElement, _cursor, _detectChanges, _eqArgs, _fnElement, _fragment_, _meta, _mithril_, _mount_, _moveParent, _propagate, _quiet, _quietEvents, _redraw_, _renderCache, _rendering, _vnode, argv, asElement, assocIn, atom, children, classNames, deref, eqShallow, getIn, identical, identity, isArray, keys, merge, prepareAttrs, props, ratom, reset, second, stateAtom, swap;
var RAtom, RCursor, _createElement, _cursor, _detectChanges, _eqArgs, _fnElement, _fragment_, _meta, _mithril_, _mount_, _moveParent, _propagate, _quiet, _quietEvents, _redraw_, _renderCache, _rendering, _vnode, _with, argv, asElement, assocIn, atom, children, classNames, deref, eqShallow, getIn, identical, identity, isArray, keys, merge, prepareAttrs, props, ratom, reset, second, stateAtom, swap;

({identical, eqShallow, isArray, keys, getIn, merge, assocIn, identity} = require('./util'));

Expand Down Expand Up @@ -580,7 +598,7 @@ require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=
};

_eqArgs = (xs, ys) => {
return (!xs && !ys) || ((xs != null ? xs.length : void 0) === (ys != null ? ys.length : void 0) && xs.every((x, i) => {
return (!xs && !ys) || ((xs != null ? xs.length : void 0) === (ys != null ? ys.length : void 0) && eqShallow(xs._meta, ys._meta) && xs.every((x, i) => {
return eqShallow(x, ys[i]);
}));
};
Expand All @@ -596,13 +614,15 @@ require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=

_rendering = (binding) => {
return function(vnode) {
var _old;
_old = _vnode;
_vnode = vnode;
try {
this._subs.clear();
this._argv = vnode.attrs.argv; // last render args
return binding.call(this, vnode);
} finally {
_vnode = null;
_vnode = _old;
}
};
};
Expand Down Expand Up @@ -691,7 +711,7 @@ require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=
};

/* Adds metadata to the Hiccup form of a Reagent component or a fragment */
exports.with = (meta, form) => {
exports.with = _with = (meta, form) => {
form = form.slice(0);
form._meta = meta;
return form;
Expand Down Expand Up @@ -810,7 +830,7 @@ require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=
/* Converts a Mithril component into a Reagent component */
exports.adaptComponent = (c) => {
return (...args) => {
return ['>', c, ...args];
return _with(_vnode != null ? _vnode.attrs : void 0, ['>', c, ...args]);
};
};

Expand Down Expand Up @@ -928,7 +948,7 @@ require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=
if (x == null) {
return x;
} else {
return x.__proto__.constructor;
return Object.getPrototypeOf(x).constructor;
}
};

Expand Down
2 changes: 1 addition & 1 deletion dist/mreframe-nodeps.min.js

Large diffs are not rendered by default.

52 changes: 39 additions & 13 deletions dist/mreframe-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,25 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :

}).call(this);

},{"./util":25}],23:[function(require,module,exports){
},{"./util":26}],23:[function(require,module,exports){
(function() {
var jsx, r;

r = require('./reagent');

jsx = (tag, {children = [], ...attrs}, key) => { // this API isn't documented properly...
return r.with({key, ...attrs}, [tag].concat(children));
};

module.exports = {
jsx,
jsxs: jsx,
Fragment: '<>'
};

}).call(this);

},{"./reagent":25}],24:[function(require,module,exports){
(function() {

/*
Expand Down Expand Up @@ -2747,9 +2765,9 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :

}).call(this);

},{"./atom":22,"./reagent":24,"./util":25}],24:[function(require,module,exports){
},{"./atom":22,"./reagent":25,"./util":26}],25:[function(require,module,exports){
(function() {
var RAtom, RCursor, _createElement, _cursor, _detectChanges, _eqArgs, _fnElement, _fragment_, _meta, _mithril_, _mount_, _moveParent, _propagate, _quiet, _quietEvents, _redraw_, _renderCache, _rendering, _vnode, argv, asElement, assocIn, atom, children, classNames, deref, eqShallow, getIn, identical, identity, isArray, keys, merge, prepareAttrs, props, ratom, reset, second, stateAtom, swap;
var RAtom, RCursor, _createElement, _cursor, _detectChanges, _eqArgs, _fnElement, _fragment_, _meta, _mithril_, _mount_, _moveParent, _propagate, _quiet, _quietEvents, _redraw_, _renderCache, _rendering, _vnode, _with, argv, asElement, assocIn, atom, children, classNames, deref, eqShallow, getIn, identical, identity, isArray, keys, merge, prepareAttrs, props, ratom, reset, second, stateAtom, swap;

({identical, eqShallow, isArray, keys, getIn, merge, assocIn, identity} = require('./util'));

Expand Down Expand Up @@ -2787,7 +2805,7 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
};

_eqArgs = (xs, ys) => {
return (!xs && !ys) || ((xs != null ? xs.length : void 0) === (ys != null ? ys.length : void 0) && xs.every((x, i) => {
return (!xs && !ys) || ((xs != null ? xs.length : void 0) === (ys != null ? ys.length : void 0) && eqShallow(xs._meta, ys._meta) && xs.every((x, i) => {
return eqShallow(x, ys[i]);
}));
};
Expand All @@ -2803,13 +2821,15 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :

_rendering = (binding) => {
return function(vnode) {
var _old;
_old = _vnode;
_vnode = vnode;
try {
this._subs.clear();
this._argv = vnode.attrs.argv; // last render args
return binding.call(this, vnode);
} finally {
_vnode = null;
_vnode = _old;
}
};
};
Expand Down Expand Up @@ -2898,7 +2918,7 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
};

/* Adds metadata to the Hiccup form of a Reagent component or a fragment */
exports.with = (meta, form) => {
exports.with = _with = (meta, form) => {
form = form.slice(0);
form._meta = meta;
return form;
Expand Down Expand Up @@ -3017,7 +3037,7 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
/* Converts a Mithril component into a Reagent component */
exports.adaptComponent = (c) => {
return (...args) => {
return ['>', c, ...args];
return _with(_vnode != null ? _vnode.attrs : void 0, ['>', c, ...args]);
};
};

Expand Down Expand Up @@ -3123,7 +3143,7 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :

}).call(this);

},{"./atom":22,"./util":25}],25:[function(require,module,exports){
},{"./atom":22,"./util":26}],26:[function(require,module,exports){
(function() {
var _dict, _entries, assoc, assocIn, entries, eq, eqArr, eqObj, eqObjShallow, eqShallow, flatten, getIn, identical, identity, isArray, isDict, keys, merge, replacer, sorter, type, update, vals;

Expand All @@ -3135,7 +3155,7 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
if (x == null) {
return x;
} else {
return x.__proto__.constructor;
return Object.getPrototypeOf(x).constructor;
}
};

Expand Down Expand Up @@ -3358,7 +3378,13 @@ module.exports = require("./api/router")(typeof window !== "undefined" ? window

}).call(this);

},{"./src/atom":22}],"mreframe/re-frame":[function(require,module,exports){
},{"./src/atom":22}],"mreframe/jsx-runtime":[function(require,module,exports){
(function() {
module.exports = require('./src/jsx-runtime');

}).call(this);

},{"./src/jsx-runtime":23}],"mreframe/re-frame":[function(require,module,exports){
(function() {
var hyperscript, mount, reFrame, redraw;

Expand All @@ -3374,7 +3400,7 @@ module.exports = require("./api/router")(typeof window !== "undefined" ? window

}).call(this);

},{"./src/re-frame":23,"mithril/hyperscript":"mithril/hyperscript","mithril/mount":"mithril/mount","mithril/redraw":"mithril/redraw"}],"mreframe/reagent":[function(require,module,exports){
},{"./src/re-frame":24,"mithril/hyperscript":"mithril/hyperscript","mithril/mount":"mithril/mount","mithril/redraw":"mithril/redraw"}],"mreframe/reagent":[function(require,module,exports){
(function() {
var hyperscript, mount, reagent, redraw;

Expand All @@ -3390,13 +3416,13 @@ module.exports = require("./api/router")(typeof window !== "undefined" ? window

}).call(this);

},{"./src/reagent":24,"mithril/hyperscript":"mithril/hyperscript","mithril/mount":"mithril/mount","mithril/redraw":"mithril/redraw"}],"mreframe/util":[function(require,module,exports){
},{"./src/reagent":25,"mithril/hyperscript":"mithril/hyperscript","mithril/mount":"mithril/mount","mithril/redraw":"mithril/redraw"}],"mreframe/util":[function(require,module,exports){
(function() {
module.exports = require('./src/util');

}).call(this);

},{"./src/util":25}],"mreframe":[function(require,module,exports){
},{"./src/util":26}],"mreframe":[function(require,module,exports){
(function() {
var _init, atom, exports, hyperscript, mount, reFrame, reagent, redraw, util;

Expand Down
2 changes: 1 addition & 1 deletion dist/mreframe-route.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit e7ddfca

Please sign in to comment.