@mintjamsinc/ichigojs 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ichigo.esm.js +88 -17
- package/dist/ichigo.esm.js.map +1 -1
- package/dist/ichigo.esm.min.js +1 -1
- package/dist/ichigo.esm.min.js.map +1 -1
- package/dist/ichigo.umd.js +88 -17
- package/dist/ichigo.umd.js.map +1 -1
- package/dist/ichigo.umd.min.js +1 -1
- package/dist/ichigo.umd.min.js.map +1 -1
- package/dist/types/ichigo/VBindingsInit.d.ts +5 -0
- package/dist/types/ichigo/util/VLogManager.d.ts +15 -0
- package/dist/types/ichigo/util/VLogger.d.ts +31 -0
- package/package.json +1 -1
package/dist/ichigo.esm.js
CHANGED
@@ -7163,6 +7163,10 @@ class VBindings {
|
|
7163
7163
|
* The change tracker, if any.
|
7164
7164
|
*/
|
7165
7165
|
#onChange;
|
7166
|
+
/**
|
7167
|
+
* The logger instance.
|
7168
|
+
*/
|
7169
|
+
#logger;
|
7166
7170
|
/**
|
7167
7171
|
* The set of changed identifiers.
|
7168
7172
|
*/
|
@@ -7178,6 +7182,10 @@ class VBindings {
|
|
7178
7182
|
constructor(args = {}) {
|
7179
7183
|
this.#parent = args.parent;
|
7180
7184
|
this.#onChange = args.onChange;
|
7185
|
+
this.#logger = args.vApplication?.logManager.getLogger('VBindings');
|
7186
|
+
if (this.#logger?.isDebugEnabled) {
|
7187
|
+
this.#logger.debug(`VBindings created. Parent: ${this.#parent ? 'yes' : 'no'}`);
|
7188
|
+
}
|
7181
7189
|
this.#local = new Proxy({}, {
|
7182
7190
|
get: (obj, key) => {
|
7183
7191
|
if (Reflect.has(obj, key)) {
|
@@ -7202,6 +7210,7 @@ class VBindings {
|
|
7202
7210
|
let path = '';
|
7203
7211
|
for (const part of changedPath?.split('.') || []) {
|
7204
7212
|
path = path ? `${path}.${part}` : part;
|
7213
|
+
this.#logger?.debug(`Binding changed: ${path}`);
|
7205
7214
|
this.#changes.add(path);
|
7206
7215
|
}
|
7207
7216
|
this.#onChange?.(changedPath);
|
@@ -7212,15 +7221,22 @@ class VBindings {
|
|
7212
7221
|
// Detect changes
|
7213
7222
|
let hasChanged = oldValue !== newValue;
|
7214
7223
|
// Special handling for arrays: check length changes even if same object reference
|
7215
|
-
if (
|
7224
|
+
if (Array.isArray(newValue)) {
|
7216
7225
|
const cachedLength = this.#lengthCache.get(key);
|
7217
7226
|
const currentLength = newValue.length;
|
7218
|
-
if (cachedLength !== undefined && cachedLength !== currentLength) {
|
7227
|
+
if (!hasChanged && cachedLength !== undefined && cachedLength !== currentLength) {
|
7219
7228
|
hasChanged = true;
|
7220
7229
|
}
|
7221
7230
|
this.#lengthCache.set(key, currentLength);
|
7222
7231
|
}
|
7223
7232
|
if (hasChanged) {
|
7233
|
+
if (this.#logger?.isDebugEnabled) {
|
7234
|
+
const oldValueString = typeof oldValue === 'string' ? `"${oldValue}"` : JSON.stringify(oldValue) || 'undefined';
|
7235
|
+
const newValueString = typeof newValue === 'string' ? `"${newValue}"` : JSON.stringify(newValue) || 'undefined';
|
7236
|
+
const oldValuePreview = oldValueString.length > 100 ? `${oldValueString.substring(0, 100)}...` : oldValueString;
|
7237
|
+
const newValuePreview = newValueString.length > 100 ? `${newValueString.substring(0, 100)}...` : newValueString;
|
7238
|
+
this.#logger.debug(`Binding set on ${target === obj ? 'local' : 'parent'}: ${key}: ${oldValuePreview} -> ${newValuePreview}`);
|
7239
|
+
}
|
7224
7240
|
this.#changes.add(key);
|
7225
7241
|
this.#onChange?.(key);
|
7226
7242
|
}
|
@@ -7228,6 +7244,7 @@ class VBindings {
|
|
7228
7244
|
},
|
7229
7245
|
deleteProperty: (obj, key) => {
|
7230
7246
|
const result = Reflect.deleteProperty(obj, key);
|
7247
|
+
this.#logger?.debug(`Binding deleted: ${key}`);
|
7231
7248
|
this.#changes.add(key);
|
7232
7249
|
this.#onChange?.(key);
|
7233
7250
|
return result;
|
@@ -8941,10 +8958,13 @@ class VModelDirective {
|
|
8941
8958
|
}
|
8942
8959
|
// .number modifier: convert to number
|
8943
8960
|
if (this.#modifiers.has('number')) {
|
8944
|
-
|
8945
|
-
|
8946
|
-
|
8947
|
-
|
8961
|
+
// Skip conversion if the value is empty string
|
8962
|
+
if (result !== '') {
|
8963
|
+
const parsed = Number(result);
|
8964
|
+
// Only convert if it's a valid number
|
8965
|
+
if (!isNaN(parsed)) {
|
8966
|
+
result = parsed;
|
8967
|
+
}
|
8948
8968
|
}
|
8949
8969
|
}
|
8950
8970
|
return result;
|
@@ -9472,49 +9492,105 @@ var LogLevel;
|
|
9472
9492
|
})(LogLevel || (LogLevel = {}));
|
9473
9493
|
|
9474
9494
|
// Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
|
9495
|
+
/**
|
9496
|
+
* A simple logger class for virtual applications.
|
9497
|
+
*/
|
9475
9498
|
class VLogger {
|
9499
|
+
/** The name of the logger. */
|
9476
9500
|
#name;
|
9501
|
+
/** The log manager instance. */
|
9477
9502
|
#logManager;
|
9478
9503
|
constructor(name, logManager) {
|
9479
9504
|
this.#name = name;
|
9480
9505
|
this.#logManager = logManager;
|
9481
9506
|
}
|
9507
|
+
/**
|
9508
|
+
* Indicates whether the debug level is enabled.
|
9509
|
+
*/
|
9510
|
+
get isDebugEnabled() {
|
9511
|
+
return [LogLevel.DEBUG].includes(this.#logManager.logLevel);
|
9512
|
+
}
|
9513
|
+
/**
|
9514
|
+
* Indicates whether the info level is enabled.
|
9515
|
+
*/
|
9516
|
+
get isInfoEnabled() {
|
9517
|
+
return [LogLevel.DEBUG, LogLevel.INFO].includes(this.#logManager.logLevel);
|
9518
|
+
}
|
9519
|
+
/**
|
9520
|
+
* Indicates whether the warn level is enabled.
|
9521
|
+
*/
|
9522
|
+
get isWarnEnabled() {
|
9523
|
+
return [LogLevel.DEBUG, LogLevel.INFO, LogLevel.WARN].includes(this.#logManager.logLevel);
|
9524
|
+
}
|
9525
|
+
/**
|
9526
|
+
* Logs a debug message.
|
9527
|
+
* @param message The message to log.
|
9528
|
+
*/
|
9482
9529
|
debug(message) {
|
9483
|
-
if (!
|
9530
|
+
if (!this.isDebugEnabled) {
|
9484
9531
|
return;
|
9485
9532
|
}
|
9486
9533
|
console.debug(`[${this.#name}] ${LogLevel.DEBUG}: ${message}`);
|
9487
9534
|
}
|
9535
|
+
/**
|
9536
|
+
* Logs an info message.
|
9537
|
+
* @param message The message to log.
|
9538
|
+
*/
|
9488
9539
|
info(message) {
|
9489
|
-
if (!
|
9540
|
+
if (!this.isInfoEnabled) {
|
9490
9541
|
return;
|
9491
9542
|
}
|
9492
9543
|
console.info(`[${this.#name}] ${LogLevel.INFO}: ${message}`);
|
9493
9544
|
}
|
9545
|
+
/**
|
9546
|
+
* Logs a warn message.
|
9547
|
+
* @param message The message to log.
|
9548
|
+
*/
|
9494
9549
|
warn(message) {
|
9495
|
-
if (!
|
9550
|
+
if (!this.isWarnEnabled) {
|
9496
9551
|
return;
|
9497
9552
|
}
|
9498
9553
|
console.warn(`[${this.#name}] ${LogLevel.WARN}: ${message}`);
|
9499
9554
|
}
|
9555
|
+
/**
|
9556
|
+
* Logs an error message.
|
9557
|
+
* @param message The message to log.
|
9558
|
+
*/
|
9500
9559
|
error(message) {
|
9501
9560
|
console.error(`[${this.#name}] ${LogLevel.ERROR}: ${message}`);
|
9502
9561
|
}
|
9503
9562
|
}
|
9504
9563
|
|
9505
9564
|
// Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
|
9565
|
+
/**
|
9566
|
+
* Manages loggers and their log levels.
|
9567
|
+
*/
|
9506
9568
|
class VLogManager {
|
9569
|
+
/** The current log level. */
|
9507
9570
|
#logLevel;
|
9571
|
+
/** A map of logger instances by name. */
|
9508
9572
|
#loggers = new Map();
|
9509
9573
|
constructor(logLevel = LogLevel.INFO) {
|
9510
9574
|
this.#logLevel = logLevel;
|
9511
9575
|
}
|
9576
|
+
/**
|
9577
|
+
* Sets the log level for all loggers.
|
9578
|
+
* @param level The log level to set.
|
9579
|
+
*/
|
9512
9580
|
set logLevel(level) {
|
9513
9581
|
this.#logLevel = level;
|
9514
9582
|
}
|
9583
|
+
/**
|
9584
|
+
* Gets the current log level.
|
9585
|
+
*/
|
9515
9586
|
get logLevel() {
|
9516
9587
|
return this.#logLevel;
|
9517
9588
|
}
|
9589
|
+
/**
|
9590
|
+
* Gets a logger by name, creating it if it doesn't exist.
|
9591
|
+
* @param name The name of the logger.
|
9592
|
+
* @returns The logger instance.
|
9593
|
+
*/
|
9518
9594
|
getLogger(name) {
|
9519
9595
|
if (this.#loggers.has(name)) {
|
9520
9596
|
return this.#loggers.get(name);
|
@@ -9686,7 +9762,8 @@ class VApplication {
|
|
9686
9762
|
this.#bindings = new VBindings({
|
9687
9763
|
onChange: (identifier) => {
|
9688
9764
|
this.#scheduleUpdate();
|
9689
|
-
}
|
9765
|
+
},
|
9766
|
+
vApplication: this
|
9690
9767
|
});
|
9691
9768
|
// Inject utility methods into bindings
|
9692
9769
|
this.#bindings.set('$nextTick', (callback) => this.#nextTick(callback));
|
@@ -9790,13 +9867,7 @@ class VApplication {
|
|
9790
9867
|
// Track if the computed value actually changed
|
9791
9868
|
if (oldValue !== newValue) {
|
9792
9869
|
this.#bindings?.set(key, newValue);
|
9793
|
-
|
9794
|
-
allChanges.add(id);
|
9795
|
-
const idx = id.indexOf('[');
|
9796
|
-
if (idx !== -1) {
|
9797
|
-
allChanges.add(id.substring(0, idx));
|
9798
|
-
}
|
9799
|
-
});
|
9870
|
+
allChanges.add(key);
|
9800
9871
|
}
|
9801
9872
|
}
|
9802
9873
|
catch (error) {
|