Socket
Socket
Sign inDemoInstall

mobservable

Package Overview
Dependencies
0
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.5 to 1.1.6

9

CHANGELOG.md

@@ -0,1 +1,10 @@

# 1.1.6
* Introduced `mobservable.fastArray(array)`, in addition to `mobservable.observable(array)`. Which is much faster when adding items but doesn't support enumerability (`for (var idx in ar) ..` loops).
* Introduced `observableArray.peek()`, for fast access to the array values. Should be used read-only.
# 1.1.5
* Fixed 71: transactions should not influence running computations
# 1.1.4

@@ -2,0 +11,0 @@

1

lib/core.d.ts

@@ -11,2 +11,3 @@ import { Lambda, IObservableArray, IObservableValue, IContextInfoStruct, IArrayChange, IArraySplice, IObjectChange } from './interfaces';

export declare function map<V>(initialValues?: KeyValueMap<V>, valueModifier?: Function): ObservableMap<V>;
export declare function fastArray<V>(initialValues?: V[]): IObservableArray<V>;
export declare function asReference<T>(value: T): T;

@@ -13,0 +14,0 @@ export declare function asStructure<T>(value: T): T;

@@ -57,2 +57,6 @@ /**

exports.map = map;
function fastArray(initialValues) {
return observablearray_1.createObservableArray(initialValues, ValueMode.Flat, false, null);
}
exports.fastArray = fastArray;
function asReference(value) {

@@ -431,3 +435,3 @@ return new AsReference(value);

if (Array.isArray(value))
return observablearray_1.createObservableArray(value.slice(), childMode, context);
return observablearray_1.createObservableArray(value, childMode, true, context);
if (utils_1.isPlainObject(value))

@@ -434,0 +438,0 @@ return extendObservableHelper(value, value, childMode, context);

2

lib/index.d.ts
import { IDependencyTree, IObserverTree, ITransitionEvent, Lambda } from './interfaces';
import SimpleEventEmitter from './simpleeventemitter';
export * from './interfaces';
export { isObservable, isObservableObject, isObservableArray, isObservableMap, observable, extendObservable, asReference, asFlat, asStructure, observe, autorun, autorunUntil, autorunAsync, expr, toJSON, isObservable as isReactive, map, observable as makeReactive, extendObservable as extendReactive, autorunUntil as observeUntil, autorunAsync as observeAsync } from './core';
export { isObservable, isObservableObject, isObservableArray, isObservableMap, observable, extendObservable, asReference, asFlat, asStructure, observe, autorun, autorunUntil, autorunAsync, expr, toJSON, isObservable as isReactive, map, fastArray, observable as makeReactive, extendObservable as extendReactive, autorunUntil as observeUntil, autorunAsync as observeAsync } from './core';
export { untracked, transaction } from './dnode';

@@ -6,0 +6,0 @@ export { ObservableMap } from './observablemap';

@@ -28,2 +28,3 @@ function __export(m) {

exports.map = core_1.map;
exports.fastArray = core_1.fastArray;
exports.makeReactive = core_1.observable;

@@ -30,0 +31,0 @@ exports.extendReactive = core_1.extendObservable;

@@ -22,2 +22,3 @@ export interface IContextInfoStruct {

clear(): T[];
peek(): T[];
replace(newItems: T[]): T[];

@@ -24,0 +25,0 @@ find(predicate: (item: T, index: number, array: IObservableArray<T>) => boolean, thisArg?: any, fromIndex?: number): T;

@@ -8,10 +8,12 @@ import { DataNode } from './dnode';

export declare class ObservableArrayAdministration<T> extends DataNode {
private array;
array: ObservableArray<T>;
mode: ValueMode;
supportEnumerable: boolean;
values: T[];
changeEvent: SimpleEventEmitter;
constructor(array: ObservableArray<T>, mode: ValueMode, context: IContextInfoStruct);
lastKnownLength: number;
constructor(array: ObservableArray<T>, mode: ValueMode, supportEnumerable: boolean, context: IContextInfoStruct);
getLength(): number;
setLength(newLength: any): number;
private updateLength(oldLength, delta);
updateLength(oldLength: number, delta: number): void;
spliceWithArray(index: number, deleteCount?: number, newItems?: T[]): T[];

@@ -23,6 +25,6 @@ makeReactiveArrayItem(value: any): any;

}
export declare function createObservableArray<T>(initialValues: T[], mode: ValueMode, context: IContextInfoStruct): IObservableArray<T>;
export declare function createObservableArray<T>(initialValues: T[], mode: ValueMode, supportEnumerable: boolean, context: IContextInfoStruct): IObservableArray<T>;
export declare class ObservableArray<T> extends StubArray {
$mobservable: ObservableArrayAdministration<T>;
constructor(initialValues: T[], mode: ValueMode, context: IContextInfoStruct);
constructor(initialValues: T[], mode: ValueMode, supportEnumerable: boolean, context: IContextInfoStruct);
observe(listener: (changeData: IArrayChange<T> | IArraySplice<T>) => void, fireImmediately?: boolean): Lambda;

@@ -32,2 +34,3 @@ clear(): T[];

toJSON(): T[];
peek(): T[];
find(predicate: (item: T, index: number, array: ObservableArray<T>) => boolean, thisArg?: any, fromIndex?: number): T;

@@ -34,0 +37,0 @@ splice(index: number, deleteCount?: number, ...newItems: T[]): T[];

@@ -24,8 +24,8 @@ /**

__extends(ObservableArrayAdministration, _super);
function ObservableArrayAdministration(array, mode, context) {
function ObservableArrayAdministration(array, mode, supportEnumerable, context) {
_super.call(this, context ? context : { name: undefined, object: undefined });
this.array = array;
this.mode = mode;
this.values = [];
this.changeEvent = new simpleeventemitter_1.default();
this.supportEnumerable = supportEnumerable;
this.lastKnownLength = 0;
if (!this.context.object)

@@ -50,6 +50,10 @@ this.context.object = array;

ObservableArrayAdministration.prototype.updateLength = function (oldLength, delta) {
if (oldLength !== this.lastKnownLength)
throw new Error("[mobservable] Modification exception: the internal structure of an observable array was changed. Did you use peek() to change it?");
this.lastKnownLength += delta;
if (delta < 0) {
dnode_1.checkIfStateIsBeingModifiedDuringView(this.context);
for (var i = oldLength + delta; i < oldLength; i++)
delete this.array[i];
if (this.supportEnumerable)
for (var i = oldLength + delta; i < oldLength; i++)
delete this.array[i];
}

@@ -60,4 +64,5 @@ else if (delta > 0) {

reserveArrayBuffer(oldLength + delta);
for (var i = oldLength, end = oldLength + delta; i < end; i++)
Object.defineProperty(this.array, i, ENUMERABLE_PROPS[i]);
if (this.supportEnumerable)
for (var i = oldLength, end = oldLength + delta; i < end; i++)
Object.defineProperty(this.array, i, ENUMERABLE_PROPS[i]);
}

@@ -102,3 +107,4 @@ };

this.notifyChanged();
this.changeEvent.emit({ object: this.array, type: 'update', index: index, oldValue: oldValue });
if (this.changeEvent)
this.changeEvent.emit({ object: this.array, type: 'update', index: index, oldValue: oldValue });
};

@@ -109,3 +115,4 @@ ObservableArrayAdministration.prototype.notifySplice = function (index, deleted, added) {

this.notifyChanged();
this.changeEvent.emit({ object: this.array, type: 'splice', index: index, addedCount: added.length, removed: deleted });
if (this.changeEvent)
this.changeEvent.emit({ object: this.array, type: 'splice', index: index, addedCount: added.length, removed: deleted });
};

@@ -119,4 +126,4 @@ ObservableArrayAdministration.prototype.notifyChanged = function () {

exports.ObservableArrayAdministration = ObservableArrayAdministration;
function createObservableArray(initialValues, mode, context) {
return new ObservableArray(initialValues, mode, context);
function createObservableArray(initialValues, mode, supportEnumerable, context) {
return new ObservableArray(initialValues, mode, supportEnumerable, context);
}

@@ -126,14 +133,21 @@ exports.createObservableArray = createObservableArray;

__extends(ObservableArray, _super);
function ObservableArray(initialValues, mode, context) {
function ObservableArray(initialValues, mode, supportEnumerable, context) {
_super.call(this);
var adm = new ObservableArrayAdministration(this, mode, supportEnumerable, context);
Object.defineProperty(this, "$mobservable", {
enumerable: false,
configurable: false,
value: new ObservableArrayAdministration(this, mode, context)
value: adm
});
if (initialValues && initialValues.length)
this.replace(initialValues);
if (initialValues && initialValues.length) {
adm.updateLength(0, initialValues.length);
adm.values = initialValues.map(function (v) { return adm.makeReactiveArrayItem(v); });
}
else
adm.values = [];
}
ObservableArray.prototype.observe = function (listener, fireImmediately) {
if (fireImmediately === void 0) { fireImmediately = false; }
if (this.$mobservable.changeEvent === undefined)
this.$mobservable.changeEvent = new simpleeventemitter_1.default();
if (fireImmediately)

@@ -153,2 +167,6 @@ listener({ object: this, type: 'splice', index: 0, addedCount: this.$mobservable.values.length, removed: [] });

};
ObservableArray.prototype.peek = function () {
this.$mobservable.notifyObserved();
return this.$mobservable.values;
};
ObservableArray.prototype.find = function (predicate, thisArg, fromIndex) {

@@ -229,2 +247,3 @@ if (fromIndex === void 0) { fromIndex = 0; }

"pop",
"peek",
"push",

@@ -231,0 +250,0 @@ "remove",

@@ -13,3 +13,3 @@ var observablevalue_1 = require('./observablevalue');

this._hasMap = {};
this._keys = new observablearray_1.ObservableArray(null, core_1.ValueMode.Reference, {
this._keys = new observablearray_1.ObservableArray(null, core_1.ValueMode.Reference, false, {
name: ".keys()",

@@ -16,0 +16,0 @@ object: this

{
"name": "mobservable",
"version": "1.1.5",
"version": "1.1.6",
"description": "Observable data. Reactive functions. Simple code.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc