Skip to content

Commit 5381e1d

Browse files
authored
feat: Add debug mode to nextTick (#63)
* feat: Add debug mode to nextTick * chomre: bump vesion * refactor: Changed the pointing address of the resource * fix: more link --------- Co-authored-by: huang yao <5945154+kirakiray@users.noreply.github.com>
1 parent 5141248 commit 5381e1d

File tree

11 files changed

+115
-20
lines changed

11 files changed

+115
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Before using the Stanz library, it's important to understand some basic concepts
3737
- **Instance** : The object or array instance that Stanz operates on.
3838
- **Watch** : Use the `watch` method to monitor changes in instance properties.<!-- - **Path**: The location of a property in the instance, which can be specified using dot notation. -->
3939

40-
Please open the debug mode and visit the corresponding file in the [examples](https://github.com/kirakiray/stanz/tree/main/examples) directory to quickly understand the usage of stanz. Click [here](https://kirakiray.github.io/stanz/examples/watch.html) to access the online example of "watch", which is particularly useful for understanding the functionality of stanz.
40+
Please open the debug mode and visit the corresponding file in the [examples](https://github.com/ofajs/stanz/tree/main/examples) directory to quickly understand the usage of stanz. Click [here](https://ofajs.github.io/stanz/examples/watch.html) to access the online example of "watch", which is particularly useful for understanding the functionality of stanz.
4141

4242
## Creating an Instance
4343

dist/stanz.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! stanz - v8.1.27 https://github.com/kirakiray/stanz (c) 2018-2024 YAO
1+
//! stanz - v8.1.28 https://github.com/ofajs/stanz (c) 2018-2024 YAO
22
(function (global, factory) {
33
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
44
typeof define === 'function' && define.amd ? define(factory) :
@@ -19,15 +19,45 @@
1919
return type === "array" || type === "object";
2020
};
2121

22+
const isDebug = {
23+
value: null,
24+
};
25+
26+
if (typeof document !== "undefined") {
27+
if (document.currentScript) {
28+
isDebug.value = document.currentScript.attributes.hasOwnProperty("debug");
29+
} else {
30+
isDebug.value = true;
31+
}
32+
}
33+
2234
let asyncsCounter = 0;
2335
let afterTimer;
2436
const tickSets = new Set();
2537
function nextTick(callback) {
26-
const tickId = `t-${getRandomId()}`;
2738
clearTimeout(afterTimer);
2839
afterTimer = setTimeout(() => {
2940
asyncsCounter = 0;
3041
});
42+
43+
if (isDebug.value) {
44+
Promise.resolve().then(() => {
45+
asyncsCounter++;
46+
if (asyncsCounter > 100000) {
47+
const desc = `nextTick exceeds thread limit`;
48+
console.error({
49+
desc,
50+
lastCall: callback,
51+
});
52+
throw new Error(desc);
53+
}
54+
55+
callback();
56+
});
57+
return;
58+
}
59+
60+
const tickId = `t-${getRandomId()}`;
3161
tickSets.add(tickId);
3262
Promise.resolve().then(() => {
3363
asyncsCounter++;
@@ -49,6 +79,8 @@
4979
return tickId;
5080
}
5181

82+
// export const clearTick = (id) => tickSets.delete(id);
83+
5284
function debounce(func, wait = 0) {
5385
let timeout = null;
5486
let hisArgs = [];

dist/stanz.min.js

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

dist/stanz.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)