Comparing version 0.7.0 to 0.7.1
{ | ||
"name": "aurumjs", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "Stream based declarative DOM rendering library for javascript", | ||
@@ -5,0 +5,0 @@ "main": "prebuilt/cjs/aurumjs.js", |
@@ -25,3 +25,2 @@ import { DataSource, ArrayDataSource, ReadOnlyDataSource, ReadOnlyArrayDataSource } from '../stream/data_source'; | ||
onDetach(cb: () => void): void; | ||
onError(cb: (error: Error) => Renderable): void; | ||
cancellationToken: CancellationToken; | ||
@@ -28,0 +27,0 @@ prerender(children: Renderable[], lifeCycle: ComponentLifeCycle): any[]; |
@@ -307,5 +307,2 @@ "use strict"; | ||
}, | ||
onError: (cb) => { | ||
throw new Error('not implemented'); | ||
}, | ||
get cancellationToken() { | ||
@@ -312,0 +309,0 @@ if (!token) { |
@@ -0,4 +1,4 @@ | ||
import { CancellationToken } from '../utilities/cancellation_token'; | ||
import { Callback } from '../utilities/common'; | ||
import { ArrayDataSource, DataSource } from './data_source'; | ||
import { Callback } from '../utilities/common'; | ||
import { CancellationToken } from '../utilities/cancellation_token'; | ||
import { DuplexDataSource } from './duplex_data_source'; | ||
@@ -17,2 +17,4 @@ export interface ObjectChange<T, K extends keyof T> { | ||
static toObjectDataSource<T>(value: T | ObjectDataSource<T>): ObjectDataSource<T>; | ||
pickObject<K extends keyof T>(key: K, cancellationToken?: CancellationToken): ObjectDataSource<T[K]>; | ||
pickArray<K extends keyof T>(key: K, cancellationToken?: CancellationToken): ArrayDataSource<FlatArray<T[K], 1>>; | ||
/** | ||
@@ -78,2 +80,12 @@ * Creates a datasource for a single key of the object | ||
/** | ||
* Merge the key value pairs of an object into this object non recursively and delete properties that do not exist in the newData | ||
* @param newData | ||
*/ | ||
merge(newData: Partial<T> | ObjectDataSource<T>): void; | ||
/** | ||
* Deletes all keys | ||
*/ | ||
clear(): void; | ||
getData(): Readonly<T>; | ||
/** | ||
* Returns a shallow copy of the object | ||
@@ -80,0 +92,0 @@ */ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ObjectDataSource = void 0; | ||
const event_emitter_1 = require("../utilities/event_emitter"); | ||
const data_source_1 = require("./data_source"); | ||
const event_emitter_1 = require("../utilities/event_emitter"); | ||
const duplex_data_source_1 = require("./duplex_data_source"); | ||
@@ -21,2 +21,52 @@ class ObjectDataSource { | ||
} | ||
pickObject(key, cancellationToken) { | ||
if (typeof this.data[key] === 'object') { | ||
const subDataSource = new ObjectDataSource(this.data[key]); | ||
subDataSource.listen((change) => { | ||
if (change.deleted) { | ||
delete this.data[key][change.key]; | ||
} | ||
else { | ||
this.get(key)[change.key] = change.newValue; | ||
} | ||
}, cancellationToken); | ||
this.listenOnKey(key, (v) => { | ||
if (typeof v.newValue === 'object') { | ||
if (v.newValue !== subDataSource.data) { | ||
subDataSource.merge(v.newValue); | ||
} | ||
} | ||
else { | ||
subDataSource.clear(); | ||
} | ||
}); | ||
return subDataSource; | ||
} | ||
else { | ||
throw new Error('Cannot pick a non object key'); | ||
} | ||
} | ||
pickArray(key, cancellationToken) { | ||
var _a; | ||
if (Array.isArray(this.data[key])) { | ||
const subDataSource = new data_source_1.ArrayDataSource((_a = this.data) === null || _a === void 0 ? void 0 : _a[key]); | ||
subDataSource.listen((change) => { | ||
this.set(key, change.newState); | ||
}, cancellationToken); | ||
this.listenOnKey(key, (v) => { | ||
if (Array.isArray(v.newValue)) { | ||
if (v.newValue.length !== subDataSource.length.value || !subDataSource.getData().every((item, index) => v.newValue[index] === item)) { | ||
subDataSource.merge(v.newValue); | ||
} | ||
} | ||
else { | ||
subDataSource.clear(); | ||
} | ||
}); | ||
return subDataSource; | ||
} | ||
else { | ||
throw new Error('Cannot pick a non array key'); | ||
} | ||
} | ||
/** | ||
@@ -30,4 +80,9 @@ * Creates a datasource for a single key of the object | ||
const subDataSource = new data_source_1.DataSource((_a = this.data) === null || _a === void 0 ? void 0 : _a[key]); | ||
subDataSource.listen(() => { | ||
this.set(key, subDataSource.value); | ||
}, cancellationToken); | ||
this.listenOnKey(key, (v) => { | ||
subDataSource.update(v.newValue); | ||
if (subDataSource.value !== v.newValue) { | ||
subDataSource.update(v.newValue); | ||
} | ||
}, cancellationToken); | ||
@@ -183,2 +238,35 @@ return subDataSource; | ||
/** | ||
* Merge the key value pairs of an object into this object non recursively and delete properties that do not exist in the newData | ||
* @param newData | ||
*/ | ||
merge(newData) { | ||
const keys = new Set(Object.keys(this.data)); | ||
if (newData instanceof ObjectDataSource) { | ||
for (const key of newData.keys()) { | ||
keys.delete(key); | ||
this.set(key, newData.data[key]); | ||
} | ||
} | ||
else { | ||
for (const key of Object.keys(newData)) { | ||
keys.delete(key); | ||
this.set(key, newData[key]); | ||
} | ||
} | ||
for (const key of keys) { | ||
this.delete(key); | ||
} | ||
} | ||
/** | ||
* Deletes all keys | ||
*/ | ||
clear() { | ||
for (const key in this.data) { | ||
this.delete(key); | ||
} | ||
} | ||
getData() { | ||
return this.data; | ||
} | ||
/** | ||
* Returns a shallow copy of the object | ||
@@ -185,0 +273,0 @@ */ |
@@ -25,3 +25,2 @@ import { DataSource, ArrayDataSource, ReadOnlyDataSource, ReadOnlyArrayDataSource } from '../stream/data_source'; | ||
onDetach(cb: () => void): void; | ||
onError(cb: (error: Error) => Renderable): void; | ||
cancellationToken: CancellationToken; | ||
@@ -28,0 +27,0 @@ prerender(children: Renderable[], lifeCycle: ComponentLifeCycle): any[]; |
@@ -305,5 +305,2 @@ import { diagnosticMode } from '../debug_mode'; | ||
}, | ||
onError: (cb) => { | ||
throw new Error('not implemented'); | ||
}, | ||
get cancellationToken() { | ||
@@ -310,0 +307,0 @@ if (!token) { |
@@ -0,4 +1,4 @@ | ||
import { CancellationToken } from '../utilities/cancellation_token'; | ||
import { Callback } from '../utilities/common'; | ||
import { ArrayDataSource, DataSource } from './data_source'; | ||
import { Callback } from '../utilities/common'; | ||
import { CancellationToken } from '../utilities/cancellation_token'; | ||
import { DuplexDataSource } from './duplex_data_source'; | ||
@@ -17,2 +17,4 @@ export interface ObjectChange<T, K extends keyof T> { | ||
static toObjectDataSource<T>(value: T | ObjectDataSource<T>): ObjectDataSource<T>; | ||
pickObject<K extends keyof T>(key: K, cancellationToken?: CancellationToken): ObjectDataSource<T[K]>; | ||
pickArray<K extends keyof T>(key: K, cancellationToken?: CancellationToken): ArrayDataSource<FlatArray<T[K], 1>>; | ||
/** | ||
@@ -78,2 +80,12 @@ * Creates a datasource for a single key of the object | ||
/** | ||
* Merge the key value pairs of an object into this object non recursively and delete properties that do not exist in the newData | ||
* @param newData | ||
*/ | ||
merge(newData: Partial<T> | ObjectDataSource<T>): void; | ||
/** | ||
* Deletes all keys | ||
*/ | ||
clear(): void; | ||
getData(): Readonly<T>; | ||
/** | ||
* Returns a shallow copy of the object | ||
@@ -80,0 +92,0 @@ */ |
@@ -0,3 +1,3 @@ | ||
import { EventEmitter } from '../utilities/event_emitter'; | ||
import { ArrayDataSource, DataSource } from './data_source'; | ||
import { EventEmitter } from '../utilities/event_emitter'; | ||
import { DuplexDataSource } from './duplex_data_source'; | ||
@@ -21,2 +21,51 @@ export class ObjectDataSource { | ||
} | ||
pickObject(key, cancellationToken) { | ||
if (typeof this.data[key] === 'object') { | ||
const subDataSource = new ObjectDataSource(this.data[key]); | ||
subDataSource.listen((change) => { | ||
if (change.deleted) { | ||
delete this.data[key][change.key]; | ||
} | ||
else { | ||
this.get(key)[change.key] = change.newValue; | ||
} | ||
}, cancellationToken); | ||
this.listenOnKey(key, (v) => { | ||
if (typeof v.newValue === 'object') { | ||
if (v.newValue !== subDataSource.data) { | ||
subDataSource.merge(v.newValue); | ||
} | ||
} | ||
else { | ||
subDataSource.clear(); | ||
} | ||
}); | ||
return subDataSource; | ||
} | ||
else { | ||
throw new Error('Cannot pick a non object key'); | ||
} | ||
} | ||
pickArray(key, cancellationToken) { | ||
if (Array.isArray(this.data[key])) { | ||
const subDataSource = new ArrayDataSource(this.data?.[key]); | ||
subDataSource.listen((change) => { | ||
this.set(key, change.newState); | ||
}, cancellationToken); | ||
this.listenOnKey(key, (v) => { | ||
if (Array.isArray(v.newValue)) { | ||
if (v.newValue.length !== subDataSource.length.value || !subDataSource.getData().every((item, index) => v.newValue[index] === item)) { | ||
subDataSource.merge(v.newValue); | ||
} | ||
} | ||
else { | ||
subDataSource.clear(); | ||
} | ||
}); | ||
return subDataSource; | ||
} | ||
else { | ||
throw new Error('Cannot pick a non array key'); | ||
} | ||
} | ||
/** | ||
@@ -29,4 +78,9 @@ * Creates a datasource for a single key of the object | ||
const subDataSource = new DataSource(this.data?.[key]); | ||
subDataSource.listen(() => { | ||
this.set(key, subDataSource.value); | ||
}, cancellationToken); | ||
this.listenOnKey(key, (v) => { | ||
subDataSource.update(v.newValue); | ||
if (subDataSource.value !== v.newValue) { | ||
subDataSource.update(v.newValue); | ||
} | ||
}, cancellationToken); | ||
@@ -181,2 +235,35 @@ return subDataSource; | ||
/** | ||
* Merge the key value pairs of an object into this object non recursively and delete properties that do not exist in the newData | ||
* @param newData | ||
*/ | ||
merge(newData) { | ||
const keys = new Set(Object.keys(this.data)); | ||
if (newData instanceof ObjectDataSource) { | ||
for (const key of newData.keys()) { | ||
keys.delete(key); | ||
this.set(key, newData.data[key]); | ||
} | ||
} | ||
else { | ||
for (const key of Object.keys(newData)) { | ||
keys.delete(key); | ||
this.set(key, newData[key]); | ||
} | ||
} | ||
for (const key of keys) { | ||
this.delete(key); | ||
} | ||
} | ||
/** | ||
* Deletes all keys | ||
*/ | ||
clear() { | ||
for (const key in this.data) { | ||
this.delete(key); | ||
} | ||
} | ||
getData() { | ||
return this.data; | ||
} | ||
/** | ||
* Returns a shallow copy of the object | ||
@@ -183,0 +270,0 @@ */ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4283279
291
40206