Skip to content

Commit ef09c47

Browse files
author
Ajit Kumar
committed
feat(isRef, isReactive static methods)
1 parent 8470101 commit ef09c47

File tree

8 files changed

+24
-8
lines changed

8 files changed

+24
-8
lines changed

dist/Ref.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reactive.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reactive.md

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const message = Reactive('Hello');
5656
| Method | Description |
5757
|-----------|-------------------------------------------------|
5858
| `toString()` | Returns string representation of the value |
59+
| `static isReactive(value)` | Check if a value is a reactive instance |
5960

6061
## Complete Example
6162

docs/ref.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const element = myRef.el;
6060
|--------------|--------------------------------------|
6161
| `get()` | Query child elements |
6262
| `getAll()` | Query all matching child elements |
63+
| `static isRef(value)` | Check if a value is a reference instance |
6364

6465
```js
6566
const btn = myRef.get('#submit-btn');

examples/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ <h1>HTML-TAG-JS</h1>
2727
console.log(p);
2828
});
2929

30+
console.log('p isRef:', Ref.isRef(p));
31+
3032
dynamic.content = [
3133
(() => {
3234
return new Promise((resolve) => {
@@ -138,6 +140,10 @@ <h1>HTML-TAG-JS</h1>
138140

139141
const text = Reactive('This is a reactive text');
140142
const count = Reactive(0);
143+
144+
console.log('text isReactive:', Reactive.isReactive(text));
145+
console.log('count isReactive:', Reactive.isReactive(count));
146+
141147
app.append(
142148
tag('hr'),
143149
tag('p', {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
}
8282
},
8383
"scripts": {
84-
"build": "webpack",
84+
"build": "webpack --mode production",
8585
"test": "jest ./test",
8686
"dev": "nodemon --exec 'jest ./test/dev.test.js' --watch ./test --watch ./jsx"
8787
},
@@ -114,4 +114,4 @@
114114
"webpack-cli": "^6.0.1"
115115
},
116116
"browserslist": "cover 100%,not android < 5"
117-
}
117+
}

src/reactive.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
class Reactive extends Text {
2+
class ReactiveClass extends Text {
33
/** @type {(value:string)=>void} */
44
onChange = null;
55

@@ -44,4 +44,8 @@ class Reactive extends Text {
4444
* @param {number|string} value - The initial value of the text node
4545
* @returns {Text}
4646
*/
47-
export default (value) => new Reactive(value);
47+
export default function Reactive(value) {
48+
return new ReactiveClass(value);
49+
}
50+
51+
Reactive.isReactive = (value) => value instanceof ReactiveClass;

src/ref.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addChildren } from './tag';
22

3-
class Ref {
3+
class RefClass {
44
instanceOfRef = true;
55
/**@type {HTMLElement} */
66
#el;
@@ -426,4 +426,8 @@ class CSSStyle {
426426
}
427427
}
428428

429-
export default (onref) => new Ref(onref);
429+
export default function Ref(onref) {
430+
return new RefClass(onref);
431+
}
432+
433+
Ref.isRef = (value) => value instanceof RefClass;

0 commit comments

Comments
 (0)