Skip to content

Commit a5c62fc

Browse files
committed
remove is() again
1 parent 2c6b1f3 commit a5c62fc

13 files changed

+22
-64
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ In the `connectedCallback()` you setup references to inner elements, add event l
1616

1717
`UIElement` is fast. In fact, faster than any JavaScript framework. Only direct fine-grained DOM updates in vanilla JavaScript can beat its performance. But then, you have no loose coupling of components and need to parse attributes and track changes yourself. This tends to get tedious and messy rather quickly. `UIElement` provides a structured way to keep your components simple, consistent and self-contained.
1818

19-
`UIElement` is tiny. 890 bytes gzipped over the wire. And it has zero dependiences. If you want to understand how it works, you have to study the source code of [one single file](./index.js).
19+
`UIElement` is tiny. 889 bytes gzipped over the wire. And it has zero dependiences. If you want to understand how it works, you have to study the source code of [one single file](./index.js).
2020

2121
That's all.
2222

@@ -246,7 +246,7 @@ It consists of three functions:
246246
- `derive()` returns a getter function for the current value of the derived computation
247247
- `effect()` accepts a callback function to be exectuted when used signals change
248248

249-
Cause & Effect is possibly the simplest way to turn JavaScript into a reactive language – with just 400 bytes gezipped code. By default, Cause & Effect doesn't do any memoization for derived signals but recalculates their current values each time. Contrary to general expectations, this seems to be faster in most cases. If you however are performing expensive work in computed signals or rely on the count of execution times, you should turn memoization on, by setting the second parameter of `derive()` to `true`.
249+
Cause & Effect is possibly the simplest way to turn JavaScript into a reactive language – with just 386 bytes gezipped code. By default, Cause & Effect doesn't do any memoization for derived signals but recalculates their current values each time. Contrary to general expectations, this seems to be faster in most cases. If you however are performing expensive work in computed signals or rely on the count of execution times, you should turn memoization on, by setting the second parameter of `derive()` to `true`.
250250

251251
#### Usage Example
252252

cause-effect.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,13 @@ const autorun = (effects) => {
1212
effect.run();
1313
};
1414
/* === Exported functions === */
15-
/**
16-
* Check if a given variable is a given JavaScript primitive type
17-
*
18-
* @param {string} type - JavaScript primitive type to check against
19-
* @param {unknown} value - variable to check if it is of the given JavaScript primitive type
20-
* @returns {boolean} true if supplied parameter is of the given JavaScript primitive type
21-
*/
22-
const is = (type, value) => typeof value === type;
2315
/**
2416
* Check if a given variable is a function
2517
*
2618
* @param {unknown} fn - variable to check if it is a function
2719
* @returns {boolean} true if supplied parameter is a function
2820
*/
29-
const isFunction = (fn) => is('function', fn);
21+
const isFunction = (fn) => typeof fn === 'function';
3022
/**
3123
* Check if a given variable is a reactive state
3224
*
@@ -112,4 +104,4 @@ const effect = (fn) => {
112104
next();
113105
};
114106

115-
export { cause, derive, effect, is, isFunction, isState };
107+
export { cause, derive, effect, isFunction, isState };

cause-effect.min.js

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

component.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,13 @@ const autorun = (effects) => {
1212
effect.run();
1313
};
1414
/* === Exported functions === */
15-
/**
16-
* Check if a given variable is a given JavaScript primitive type
17-
*
18-
* @param {string} type - JavaScript primitive type to check against
19-
* @param {unknown} value - variable to check if it is of the given JavaScript primitive type
20-
* @returns {boolean} true if supplied parameter is of the given JavaScript primitive type
21-
*/
22-
const is = (type, value) => typeof value === type;
2315
/**
2416
* Check if a given variable is a function
2517
*
2618
* @param {unknown} fn - variable to check if it is a function
2719
* @returns {boolean} true if supplied parameter is a function
2820
*/
29-
const isFunction = (fn) => is('function', fn);
21+
const isFunction = (fn) => typeof fn === 'function';
3022
/**
3123
* Check if a given variable is a reactive state
3224
*
@@ -125,7 +117,7 @@ class ContextRequestEvent extends Event {
125117
* @param {unknown} value - value to check if it is a string
126118
* @returns {boolean} true if supplied parameter is a string
127119
*/
128-
const isString = (value) => is('string', value);
120+
const isString = (value) => typeof value === 'string';
129121
/* === Default export === */
130122
/**
131123
* Base class for reactive custom elements
@@ -301,7 +293,7 @@ const isStylable = (node) => {
301293
* @param {unknown} value - variable to check if it is defined
302294
* @returns {boolean} true if supplied parameter is defined
303295
*/
304-
const isDefined = (value) => !is('undefined', value) && value !== null;
296+
const isDefined = (value) => typeof value !== 'undefined' && value !== null;
305297
/**
306298
* Wrapper around a native DOM element for DOM manipulation
307299
*
@@ -454,7 +446,7 @@ const asJSON = (value) => {
454446
* @param {unknown} value - value to check if it is an object
455447
* @returns {boolean} true if supplied parameter is an object
456448
*/
457-
const isObject = (value) => isDefined(value) && is('object', value);
449+
const isObject = (value) => isDefined(value) && typeof value === 'object';
458450
/* === Default export === */
459451
/**
460452
* Create a UIElement subclass for a custom element tag

component.min.js

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

index.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,13 @@ const autorun = (effects) => {
1212
effect.run();
1313
};
1414
/* === Exported functions === */
15-
/**
16-
* Check if a given variable is a given JavaScript primitive type
17-
*
18-
* @param {string} type - JavaScript primitive type to check against
19-
* @param {unknown} value - variable to check if it is of the given JavaScript primitive type
20-
* @returns {boolean} true if supplied parameter is of the given JavaScript primitive type
21-
*/
22-
const is = (type, value) => typeof value === type;
2315
/**
2416
* Check if a given variable is a function
2517
*
2618
* @param {unknown} fn - variable to check if it is a function
2719
* @returns {boolean} true if supplied parameter is a function
2820
*/
29-
const isFunction = (fn) => is('function', fn);
21+
const isFunction = (fn) => typeof fn === 'function';
3022
/**
3123
* Check if a given variable is a reactive state
3224
*

index.min.js

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

src/cause-effect.d.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ interface UIState<T> {
1515
type UIDOMInstructionQueue = (element: Element, fn: () => void) => void;
1616
type UIMaybeCleanup = void | (() => void);
1717
type UIEffectCallback = (enqueue: UIDOMInstructionQueue) => UIMaybeCleanup;
18-
/**
19-
* Check if a given variable is a given JavaScript primitive type
20-
*
21-
* @param {string} type - JavaScript primitive type to check against
22-
* @param {unknown} value - variable to check if it is of the given JavaScript primitive type
23-
* @returns {boolean} true if supplied parameter is of the given JavaScript primitive type
24-
*/
25-
declare const is: (type: string, value: unknown) => boolean;
2618
/**
2719
* Check if a given variable is a function
2820
*
@@ -61,4 +53,4 @@ declare const derive: <T>(fn: () => T, memo?: boolean) => UIComputed<T>;
6153
* @param {UIEffectCallback} fn - callback function to be executed when a state changes
6254
*/
6355
declare const effect: (fn: UIEffectCallback) => void;
64-
export { type UIState, type UIComputed, type UIEffect, type UIDOMInstructionQueue, is, isFunction, isState, cause, derive, effect };
56+
export { type UIState, type UIComputed, type UIEffect, type UIDOMInstructionQueue, isFunction, isState, cause, derive, effect };

0 commit comments

Comments
 (0)