Skip to content

Commit 98eb5b6

Browse files
committed
update examples in docs
1 parent 8722fc2 commit 98eb5b6

File tree

6 files changed

+212
-208
lines changed

6 files changed

+212
-208
lines changed

docs/main.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@ def make_component():
4646
# Modify the run function so when we exec the file
4747
# instead of running a server we mount the view.
4848
idom.run = partial(mount.add, file.stem)
49-
50-
with file.open() as f:
51-
try:
52-
exec(
53-
f.read(),
54-
{
55-
"__file__": str(file),
56-
"__name__": f"__main__.examples.{file.stem}",
57-
},
58-
)
59-
except Exception as error:
60-
raise RuntimeError(f"Failed to execute {file}") from error
49+
try:
50+
exec(
51+
file.read_text(),
52+
{
53+
"__file__": str(file.absolute()),
54+
"__name__": f"__main__.examples.{file.stem}",
55+
},
56+
)
57+
except Exception as error:
58+
raise RuntimeError(f"Failed to execute {file}") from error
6159
finally:
6260
idom.run = original_run
6361

docs/source/_static/custom.js

Lines changed: 146 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -620,147 +620,147 @@ function checkDCE() {
620620

621621
var n=function(t,s,r,e){var u;s[0]=0;for(var h=1;h<s.length;h++){var p=s[h++],a=s[h]?(s[0]|=p?1:2,r[s[h++]]):s[++h];3===p?e[0]=a:4===p?e[1]=Object.assign(e[1]||{},a):5===p?(e[1]=e[1]||{})[s[++h]]=a:6===p?e[1][s[++h]]+=a+"":p?(u=t.apply(a,n(t,a,r,["",null])),e.push(u),a[0]?s[0]|=2:(s[h-2]=0,s[h]=u)):e.push(a);}return e},t=new Map;function htm(s){var r=t.get(this);return r||(r=new Map,t.set(this,r)),(r=n(this,r.get(s)||(r.set(s,r=function(n){for(var t,s,r=1,e="",u="",h=[0],p=function(n){1===r&&(n||(e=e.replace(/^\s*\n\s*|\s*\n\s*$/g,"")))?h.push(0,n,e):3===r&&(n||e)?(h.push(3,n,e),r=2):2===r&&"..."===e&&n?h.push(4,n,0):2===r&&e&&!n?h.push(5,0,!0,e):r>=5&&((e||!n&&5===r)&&(h.push(r,0,e,s),r=6),n&&(h.push(r,n,0,s),r=6)),e="";},a=0;a<n.length;a++){a&&(1===r&&p(),p(a));for(var l=0;l<n[a].length;l++)t=n[a][l],1===r?"<"===t?(p(),h=[h],r=3):e+=t:4===r?"--"===e&&">"===t?(r=1,e=""):e=t+e[0]:u?t===u?u="":e+=t:'"'===t||"'"===t?u=t:">"===t?(p(),r=1):r&&("="===t?(r=5,s=e,e=""):"/"===t&&(r<5||">"===n[a][l+1])?(p(),3===r&&(h=h[0]),r=h,(h=h[0]).push(2,0,r),r=0):" "===t||"\t"===t||"\n"===t||"\r"===t?(p(),r=2):e+=t),3===r&&"!--"===e&&(r=4,h=h[0]);}return p(),h}(s)),r),arguments,[])).length>1?r:r[0]}
622622

623-
/*!
624-
* https://github.com/Starcounter-Jack/JSON-Patch
625-
* (c) 2017 Joachim Wester
626-
* MIT license
627-
*/
628-
var __extends = (undefined && undefined.__extends) || (function () {
629-
var extendStatics = function (d, b) {
630-
extendStatics = Object.setPrototypeOf ||
631-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
632-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
633-
return extendStatics(d, b);
634-
};
635-
return function (d, b) {
636-
extendStatics(d, b);
637-
function __() { this.constructor = d; }
638-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
639-
};
640-
})();
641-
var _hasOwnProperty = Object.prototype.hasOwnProperty;
642-
function hasOwnProperty(obj, key) {
643-
return _hasOwnProperty.call(obj, key);
644-
}
645-
function _objectKeys(obj) {
646-
if (Array.isArray(obj)) {
647-
var keys = new Array(obj.length);
648-
for (var k = 0; k < keys.length; k++) {
649-
keys[k] = "" + k;
650-
}
651-
return keys;
652-
}
653-
if (Object.keys) {
654-
return Object.keys(obj);
655-
}
656-
var keys = [];
657-
for (var i in obj) {
658-
if (hasOwnProperty(obj, i)) {
659-
keys.push(i);
660-
}
661-
}
662-
return keys;
663-
}
664-
/**
665-
* Deeply clone the object.
666-
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
667-
* @param {any} obj value to clone
668-
* @return {any} cloned obj
669-
*/
670-
function _deepClone(obj) {
671-
switch (typeof obj) {
672-
case "object":
673-
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
674-
case "undefined":
675-
return null; //this is how JSON.stringify behaves for array items
676-
default:
677-
return obj; //no need to clone primitives
678-
}
679-
}
680-
//3x faster than cached /^\d+$/.test(str)
681-
function isInteger(str) {
682-
var i = 0;
683-
var len = str.length;
684-
var charCode;
685-
while (i < len) {
686-
charCode = str.charCodeAt(i);
687-
if (charCode >= 48 && charCode <= 57) {
688-
i++;
689-
continue;
690-
}
691-
return false;
692-
}
693-
return true;
694-
}
695-
/**
696-
* Escapes a json pointer path
697-
* @param path The raw pointer
698-
* @return the Escaped path
699-
*/
700-
function escapePathComponent(path) {
701-
if (path.indexOf('/') === -1 && path.indexOf('~') === -1)
702-
return path;
703-
return path.replace(/~/g, '~0').replace(/\//g, '~1');
704-
}
705-
/**
706-
* Unescapes a json pointer path
707-
* @param path The escaped pointer
708-
* @return The unescaped path
709-
*/
710-
function unescapePathComponent(path) {
711-
return path.replace(/~1/g, '/').replace(/~0/g, '~');
712-
}
713-
/**
714-
* Recursively checks whether an object has any undefined values inside.
715-
*/
716-
function hasUndefined(obj) {
717-
if (obj === undefined) {
718-
return true;
719-
}
720-
if (obj) {
721-
if (Array.isArray(obj)) {
722-
for (var i = 0, len = obj.length; i < len; i++) {
723-
if (hasUndefined(obj[i])) {
724-
return true;
725-
}
726-
}
727-
}
728-
else if (typeof obj === "object") {
729-
var objKeys = _objectKeys(obj);
730-
var objKeysLength = objKeys.length;
731-
for (var i = 0; i < objKeysLength; i++) {
732-
if (hasUndefined(obj[objKeys[i]])) {
733-
return true;
734-
}
735-
}
736-
}
737-
}
738-
return false;
739-
}
740-
function patchErrorMessageFormatter(message, args) {
741-
var messageParts = [message];
742-
for (var key in args) {
743-
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
744-
if (typeof value !== 'undefined') {
745-
messageParts.push(key + ": " + value);
746-
}
747-
}
748-
return messageParts.join('\n');
749-
}
750-
var PatchError = /** @class */ (function (_super) {
751-
__extends(PatchError, _super);
752-
function PatchError(message, name, index, operation, tree) {
753-
var _newTarget = this.constructor;
754-
var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;
755-
_this.name = name;
756-
_this.index = index;
757-
_this.operation = operation;
758-
_this.tree = tree;
759-
Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
760-
_this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });
761-
return _this;
762-
}
763-
return PatchError;
623+
/*!
624+
* https://github.com/Starcounter-Jack/JSON-Patch
625+
* (c) 2017 Joachim Wester
626+
* MIT license
627+
*/
628+
var __extends = (undefined && undefined.__extends) || (function () {
629+
var extendStatics = function (d, b) {
630+
extendStatics = Object.setPrototypeOf ||
631+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
632+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
633+
return extendStatics(d, b);
634+
};
635+
return function (d, b) {
636+
extendStatics(d, b);
637+
function __() { this.constructor = d; }
638+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
639+
};
640+
})();
641+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
642+
function hasOwnProperty(obj, key) {
643+
return _hasOwnProperty.call(obj, key);
644+
}
645+
function _objectKeys(obj) {
646+
if (Array.isArray(obj)) {
647+
var keys = new Array(obj.length);
648+
for (var k = 0; k < keys.length; k++) {
649+
keys[k] = "" + k;
650+
}
651+
return keys;
652+
}
653+
if (Object.keys) {
654+
return Object.keys(obj);
655+
}
656+
var keys = [];
657+
for (var i in obj) {
658+
if (hasOwnProperty(obj, i)) {
659+
keys.push(i);
660+
}
661+
}
662+
return keys;
663+
}
664+
/**
665+
* Deeply clone the object.
666+
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
667+
* @param {any} obj value to clone
668+
* @return {any} cloned obj
669+
*/
670+
function _deepClone(obj) {
671+
switch (typeof obj) {
672+
case "object":
673+
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
674+
case "undefined":
675+
return null; //this is how JSON.stringify behaves for array items
676+
default:
677+
return obj; //no need to clone primitives
678+
}
679+
}
680+
//3x faster than cached /^\d+$/.test(str)
681+
function isInteger(str) {
682+
var i = 0;
683+
var len = str.length;
684+
var charCode;
685+
while (i < len) {
686+
charCode = str.charCodeAt(i);
687+
if (charCode >= 48 && charCode <= 57) {
688+
i++;
689+
continue;
690+
}
691+
return false;
692+
}
693+
return true;
694+
}
695+
/**
696+
* Escapes a json pointer path
697+
* @param path The raw pointer
698+
* @return the Escaped path
699+
*/
700+
function escapePathComponent(path) {
701+
if (path.indexOf('/') === -1 && path.indexOf('~') === -1)
702+
return path;
703+
return path.replace(/~/g, '~0').replace(/\//g, '~1');
704+
}
705+
/**
706+
* Unescapes a json pointer path
707+
* @param path The escaped pointer
708+
* @return The unescaped path
709+
*/
710+
function unescapePathComponent(path) {
711+
return path.replace(/~1/g, '/').replace(/~0/g, '~');
712+
}
713+
/**
714+
* Recursively checks whether an object has any undefined values inside.
715+
*/
716+
function hasUndefined(obj) {
717+
if (obj === undefined) {
718+
return true;
719+
}
720+
if (obj) {
721+
if (Array.isArray(obj)) {
722+
for (var i = 0, len = obj.length; i < len; i++) {
723+
if (hasUndefined(obj[i])) {
724+
return true;
725+
}
726+
}
727+
}
728+
else if (typeof obj === "object") {
729+
var objKeys = _objectKeys(obj);
730+
var objKeysLength = objKeys.length;
731+
for (var i = 0; i < objKeysLength; i++) {
732+
if (hasUndefined(obj[objKeys[i]])) {
733+
return true;
734+
}
735+
}
736+
}
737+
}
738+
return false;
739+
}
740+
function patchErrorMessageFormatter(message, args) {
741+
var messageParts = [message];
742+
for (var key in args) {
743+
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
744+
if (typeof value !== 'undefined') {
745+
messageParts.push(key + ": " + value);
746+
}
747+
}
748+
return messageParts.join('\n');
749+
}
750+
var PatchError = /** @class */ (function (_super) {
751+
__extends(PatchError, _super);
752+
function PatchError(message, name, index, operation, tree) {
753+
var _newTarget = this.constructor;
754+
var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;
755+
_this.name = name;
756+
_this.index = index;
757+
_this.operation = operation;
758+
_this.tree = tree;
759+
Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
760+
_this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });
761+
return _this;
762+
}
763+
return PatchError;
764764
}(Error));
765765

766766
var JsonPatchError = PatchError;
@@ -1381,11 +1381,11 @@ var duplex = /*#__PURE__*/Object.freeze({
13811381
compare: compare
13821382
});
13831383

1384-
var jsonpatch = Object.assign({}, core, duplex, {
1385-
JsonPatchError: PatchError,
1386-
deepClone: _deepClone,
1387-
escapePathComponent,
1388-
unescapePathComponent
1384+
var jsonpatch = Object.assign({}, core, duplex, {
1385+
JsonPatchError: PatchError,
1386+
deepClone: _deepClone,
1387+
escapePathComponent,
1388+
unescapePathComponent
13891389
});
13901390

13911391
function useJsonPatchCallback(initial) {
@@ -1967,11 +1967,6 @@ function _nextReconnectTimeout(maxReconnectTimeout, mountState) {
19671967
Math.floor(Math.random() * mountState.reconnectTimeoutRange) || 1;
19681968
mountState.reconnectTimeoutRange =
19691969
(mountState.reconnectTimeoutRange + 5) % maxReconnectTimeout;
1970-
if (mountState.reconnectAttempts === 4) {
1971-
window.alert(
1972-
"Server connection was lost. Attempts to reconnect are being made in the background."
1973-
);
1974-
}
19751970
return timeout;
19761971
}
19771972

docs/source/examples.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ you're experimenting:
6262
Define Javascript Modules
6363
-------------------------
6464

65-
Click the bars to trigger an event 👇
65+
Shows a very simple chart implemented in vanilla Javascript:
6666

6767
.. example:: super_simple_chart
6868

6969

70-
Material UI Slider
70+
Material UI Button
7171
------------------
7272

73-
Move the slider and see the event information update 👇
73+
Click the button to change the indicator 👇
7474

7575
.. example:: material_ui_switch
7676

@@ -83,6 +83,14 @@ Click the map to create pinned location 📍:
8383
.. example:: pigeon_maps
8484

8585

86+
Cytoscape Notework Graph
87+
------------------------
88+
89+
You can move the nodes in the graph 🕸️:
90+
91+
.. example:: network_graph
92+
93+
8694
.. Links
8795
.. =====
8896

0 commit comments

Comments
 (0)