Socket
Socket
Sign inDemoInstall

mobservable

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobservable - npm Package Compare versions

Comparing version 1.0.9 to 1.1.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

# 1.1.0
* Exposed `ObservableMap` type
* Introduced `mobservable.untracked(block)`
* Introduced `mobservable.autorunAsync(block, delay)`
# 1.0.9

@@ -2,0 +8,0 @@

3

lib/core.d.ts

@@ -17,7 +17,8 @@ import { Lambda, IObservableArray, IObservableValue, IContextInfoStruct, IArrayChange, IArraySplice, IObjectChange } from './interfaces';

export declare function autorunUntil(predicate: () => boolean, effect: Lambda, scope?: any): Lambda;
export declare function autorunAsyncDeprecated<T>(view: () => T, effect: (latestValue: T) => void, delay?: number, scope?: any): Lambda;
export declare function autorunAsync<T>(view: () => T, effect: (latestValue: T) => void, delay?: number, scope?: any): Lambda;
export declare function autorunAsync(func: Lambda, delay?: number, scope?: any): Lambda;
export declare function expr<T>(expr: () => T, scope?: any): T;
export declare function extendObservable<A extends Object, B extends Object>(target: A, ...properties: B[]): A & B;
export declare function toJSON(source: any): any;
export declare function transaction<T>(action: () => T): T;
export declare function getStrict(): boolean;

@@ -24,0 +25,0 @@ export declare function withStrict(newStrict: boolean, func: Lambda): void;

@@ -103,3 +103,3 @@ /**

exports.autorunUntil = autorunUntil;
function autorunAsync(view, effect, delay, scope) {
function autorunAsyncDeprecated(view, effect, delay, scope) {
if (delay === void 0) { delay = 1; }

@@ -123,2 +123,46 @@ var latestValue = undefined;

}
exports.autorunAsyncDeprecated = autorunAsyncDeprecated;
function autorunAsync(func, delay, scope) {
if (delay === void 0) { delay = 1; }
if (typeof delay === "function") {
console.warn("[mobservable] autorun(func, func) is deprecated and will removed in 2.0");
return autorunAsyncDeprecated.apply(null, arguments);
}
var shouldRun = false;
var tickScheduled = false;
var tick = observable(0);
var observedValues = [];
var disposer;
var isDisposed = false;
function schedule(f) {
setTimeout(f, delay);
}
function doTick() {
tickScheduled = false;
shouldRun = true;
tick(tick() + 1);
}
disposer = autorun(function () {
if (isDisposed)
return;
tick();
if (shouldRun) {
func.call(scope);
observedValues = disposer.$mobservable.observing;
shouldRun = false;
}
else {
observedValues.forEach(function (o) { return o.notifyObserved(); });
if (!tickScheduled) {
tickScheduled = true;
schedule(doTick);
}
}
});
return utils_1.once(function () {
isDisposed = true;
if (disposer)
disposer();
});
}
exports.autorunAsync = autorunAsync;

@@ -218,6 +262,2 @@ function expr(expr, scope) {

exports.toJSON = toJSON;
function transaction(action) {
return dnode_1.transaction(action);
}
exports.transaction = transaction;
var strict = false;

@@ -224,0 +264,0 @@ function getStrict() {

export declare function checkIfStateIsBeingModifiedDuringView(context: IContextInfoStruct): void;
export declare function transaction<T>(action: () => T): T;
export declare function untracked<T>(action: () => T): T;
export declare enum NodeState {

@@ -4,0 +5,0 @@ STALE = 0,

@@ -41,2 +41,13 @@ /**

exports.transaction = transaction;
function untracked(action) {
try {
var dnode = new ViewNode({ object: null, name: "untracked" });
global.__mobservableViewStack.push(dnode);
return action();
}
finally {
global.__mobservableViewStack.pop();
}
}
exports.untracked = untracked;
(function (NodeState) {

@@ -43,0 +54,0 @@ NodeState[NodeState["STALE"] = 0] = "STALE";

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, transaction, 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, observable as makeReactive, extendObservable as extendReactive, autorunUntil as observeUntil, autorunAsync as observeAsync } from './core';
export { untracked, transaction } from './dnode';
export { ObservableMap } from './observablemap';
export declare const _: {

@@ -6,0 +8,0 @@ isComputingView: () => boolean;

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

exports.expr = core_1.expr;
exports.transaction = core_1.transaction;
exports.toJSON = core_1.toJSON;

@@ -34,2 +33,7 @@ exports.isReactive = core_1.isObservable;

exports.observeAsync = core_1.autorunAsync;
var dnode_2 = require('./dnode');
exports.untracked = dnode_2.untracked;
exports.transaction = dnode_2.transaction;
var observablemap_1 = require('./observablemap');
exports.ObservableMap = observablemap_1.ObservableMap;
exports._ = {

@@ -36,0 +40,0 @@ isComputingView: dnode_1.isComputingView,

var observablevalue_1 = require('./observablevalue');
var core_1 = require('./core');
var simpleeventemitter_1 = require('./simpleeventemitter');
var dnode_1 = require('./dnode');
var observablearray_1 = require('./observablearray');

@@ -52,3 +53,3 @@ var utils_1 = require('./utils');

else {
core_1.transaction(function () {
dnode_1.transaction(function () {
_this._data[key] = new observablevalue_1.ObservableValue(value, _this._valueMode, {

@@ -73,3 +74,3 @@ name: "." + key,

var oldValue = this._data[key]._value;
core_1.transaction(function () {
dnode_1.transaction(function () {
_this._keys.remove(key);

@@ -124,3 +125,3 @@ _this._updateHasMapEntry(key, false);

var _this = this;
core_1.transaction(function () {
dnode_1.transaction(function () {
if (other instanceof ObservableMap)

@@ -135,3 +136,3 @@ other.keys().forEach(function (key) { return _this.set(key, other.get(key)); });

var _this = this;
core_1.transaction(function () {
dnode_1.transaction(function () {
_this.keys().forEach(_this.delete, _this);

@@ -138,0 +139,0 @@ });

{
"name": "mobservable",
"version": "1.0.9",
"version": "1.1.0",
"description": "Observable data. Reactive functions. Simple code.",

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

@@ -53,3 +53,3 @@ # mobservable

Its as simple as that. In the example above the `Timer` will automatically update each time the property `timerData.secondsPassed` is altered.
Its as simple as that. In the example above the `Timer` will automatically update each time the property `timerData.secondsPassed` is altered. This is because setter notifies the Timer observer.
The actual interesting thing about this approach are the things that are *not* in the code:

@@ -66,2 +66,6 @@

### Notice
Unlike Object.observe, you cannot track added properties. So remeber to initialize any property you want to observe. Null values work if you don't have any value yet.
Observing added properties is impossible to achieve without native Proxy support or dirty checking.
## Getting started

@@ -68,0 +72,0 @@

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc