Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fun-model

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fun-model - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

10

CHANGELOG.md
CHANGELOG
===
4.0.0
--
New Features
-
Removed createAsyncAction.
3.0.0

@@ -9,3 +17,3 @@ --

Crated bootstrapping optional parameters with state freezing option.
Created bootstrapping optional parameters with state freezing option.

@@ -12,0 +20,0 @@ 2.3.0

2

package.json
{
"name": "fun-model",
"version": "3.0.0",
"version": "4.0.0",
"description": "fun-model is pure functional implementation of FLUX architecture.",

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

@@ -112,12 +112,2 @@ "use strict";

});
it('throws on immutability violation', function () {
givenStore(aState('nestedStateValue'));
var testAction = af.createAction(SomeCursorTestFixture, function (state) {
state.nested.state = state.nested.state + 'newValue';
return state;
});
expect(function () {
testAction();
}).toThrow();
});
it('does not throw on immutability violation in no debug mode', function () {

@@ -180,70 +170,2 @@ d.bootstrap(undefined);

});
describe('createAsyncAction', function () {
beforeEach(function () {
jasmine.clock().install();
});
describe('when renderCallback has not been set', function () {
it('does not throw if action has been only declared.', function () {
var testAction = af.createAsyncAction(NestedCursorTestFixture, function (state) { return state; });
expect(testAction).not.toBeUndefined();
});
it('throws if key does not exist', function () {
expect(function () {
var testAction = af.createAsyncAction(NestedCursorTestFixture, function () { return { state: 'new nested state' }; });
testAction();
jasmine.clock().tick(1);
}).toThrow('Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).');
});
});
describe('when renderCallback has been set', function () {
var renderCallback;
beforeEach(function () {
renderCallback = jasmine.createSpy('render');
af.bootstrap(renderCallback);
});
it('does not report current state when state has not been changed.', function () {
givenStore(aState('nestedStateValue'));
var testAction = af.createAsyncAction(NestedCursorTestFixture, function (state) { return state; });
testAction();
jasmine.clock().tick(1);
expect(debugCallback).not.toHaveBeenCalledWith('Global state has been changed.', undefined);
});
it('reports state changed when debug has been enabled.', function () {
var newState = { state: 'newValue' };
givenStore(aState('nestedStateValue'));
var testAction = af.createAsyncAction(NestedCursorTestFixture, function () { return newState; });
testAction();
jasmine.clock().tick(1);
expect(debugCallback).toHaveBeenCalledWith('Global state has been changed.', undefined);
});
it('does not call render callback when state has not been changed', function () {
givenStore(aState('nestedStateValue'));
var testAction = af.createAsyncAction(NestedCursorTestFixture, function (state) { return state; });
testAction();
jasmine.clock().tick(1);
expect(renderCallback).not.toHaveBeenCalled();
});
it('calls render callback when state has been changed', function () {
givenStore(aState('nestedStateValue'));
var testAction = af.createAsyncAction(NestedCursorTestFixture, function () { return { state: 'newValue' }; });
testAction();
jasmine.clock().tick(1);
expect(renderCallback).toHaveBeenCalled();
});
it('returns new state in resolve', function (done) {
givenStore(aState('nestedStateValue'));
var newState = { state: 'newValue' };
var testAction = af.createAsyncAction(NestedCursorTestFixture, function () { return newState; });
testAction()
.then(function (r) {
expect(r).toBe(newState);
done();
});
jasmine.clock().tick(1);
});
});
afterEach(function () {
jasmine.clock().uninstall();
});
});
});

@@ -250,0 +172,0 @@ function givenStore(state) {

@@ -150,14 +150,2 @@ import * as s from '../src/store';

it('throws on immutability violation', () => {
givenStore(aState('nestedStateValue'));
const testAction = af.createAction(SomeCursorTestFixture, (state: ISomeState) => {
state.nested.state = state.nested.state + 'newValue';
return state;
});
expect(() => {
testAction();
}).toThrow();
});
it('does not throw on immutability violation in no debug mode', () => {

@@ -232,91 +220,3 @@ d.bootstrap(undefined);

});
});
describe('createAsyncAction', () => {
beforeEach(() => {
jasmine.clock().install();
});
describe('when renderCallback has not been set', () => {
it('does not throw if action has been only declared.', () => {
let testAction = af.createAsyncAction(NestedCursorTestFixture, (state: INestedState) => state);
expect(testAction).not.toBeUndefined();
});
it('throws if key does not exist', () => {
expect(() => {
let testAction = af.createAsyncAction(NestedCursorTestFixture, () => { return { state: 'new nested state' }; });
testAction();
jasmine.clock().tick(1);
}).toThrow('Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).');
});
});
describe('when renderCallback has been set', () => {
let renderCallback: () => void;
beforeEach(() => {
renderCallback = jasmine.createSpy('render');
af.bootstrap(renderCallback);
});
it('does not report current state when state has not been changed.', () => {
givenStore(aState('nestedStateValue'));
let testAction = af.createAsyncAction(NestedCursorTestFixture, (state: INestedState) => state);
testAction();
jasmine.clock().tick(1);
expect(debugCallback).not.toHaveBeenCalledWith('Global state has been changed.', undefined);
});
it('reports state changed when debug has been enabled.', () => {
let newState = { state: 'newValue' };
givenStore(aState('nestedStateValue'));
let testAction = af.createAsyncAction(NestedCursorTestFixture, () => newState);
testAction();
jasmine.clock().tick(1);
expect(debugCallback).toHaveBeenCalledWith('Global state has been changed.', undefined);
});
it('does not call render callback when state has not been changed', () => {
givenStore(aState('nestedStateValue'));
let testAction = af.createAsyncAction(NestedCursorTestFixture, (state: INestedState) => state);
testAction();
jasmine.clock().tick(1);
expect(renderCallback).not.toHaveBeenCalled();
});
it('calls render callback when state has been changed', () => {
givenStore(aState('nestedStateValue'));
let testAction = af.createAsyncAction(NestedCursorTestFixture, () => { return { state: 'newValue' }; });
testAction();
jasmine.clock().tick(1);
expect(renderCallback).toHaveBeenCalled();
});
it('returns new state in resolve', (done: Function) => {
givenStore(aState('nestedStateValue'));
let newState = { state: 'newValue' };
let testAction = af.createAsyncAction(NestedCursorTestFixture, () => newState);
testAction()
.then(r => {
expect(r).toBe(newState);
done();
});
jasmine.clock().tick(1);
});
});
afterEach(() => {
jasmine.clock().uninstall();
});
});
});
});

@@ -323,0 +223,0 @@

@@ -41,18 +41,2 @@ "use strict";

};
exports.createAsyncAction = function (cursor, handler) {
return (function (params) {
return new Promise(function (f) {
setTimeout(function () {
if (render === null)
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).';
var c = unifyCursor(cursor, params);
if (changeStateWithQueue(c, handler, params)) {
render();
d.log('Rendering invoked...');
}
f(s.getState(c));
}, 0);
});
});
};
var queueOfHandlers = [];

@@ -59,0 +43,0 @@ function changeStateWithQueue(cursor, handler, params) {

@@ -16,6 +16,2 @@ import * as s from './store';

export interface IAsyncAction<T, TState> {
(param?: T): Promise<TState>;
}
export type IActionHandler<TState extends s.IState, TParams> = (state: TState, t?: TParams) => TState;

@@ -60,20 +56,2 @@

export const createAsyncAction = <TState extends s.IState, TParams>(cursor: s.ICursor<TState> | s.ICursorFactory<TState, TParams>, handler: IActionHandler<TState, TParams>)
: IAsyncAction<TParams, TState> => {
return <IAsyncAction<TParams, TState>>((params?: TParams): Promise<TState> => {
return new Promise<TState>((f) => {
setTimeout(() => {
if (render === null)
throw 'Render callback must be set before first usage through bootstrap(defaultState, () => { yourRenderCallback(); }).';
let c = unifyCursor<TState, TParams>(cursor, params);
if (changeStateWithQueue(c, handler, params)) {
render();
d.log('Rendering invoked...');
}
f(s.getState(c));
}, 0);
});
});
}
interface IQueuedHandling<TState extends s.IState, TParams> {

@@ -80,0 +58,0 @@ cursor: s.ICursor<TState>;

@@ -22,12 +22,2 @@ "use strict";

;
// export function deepFreeze(source: any) {
// Object.freeze(source);
// for (var property in source)
// if (source.hasOwnProperty(property)
// && source[property] !== null
// && (typeof source[property] === "object" || typeof source[property] === "function")
// && !Object.isFrozen(source[property]))
// deepFreeze(source[property]);
// return source;
// };
function deepFreeze(source) {

@@ -34,0 +24,0 @@ Object.freeze(source);

@@ -23,13 +23,2 @@

// export function deepFreeze(source: any) {
// Object.freeze(source);
// for (var property in source)
// if (source.hasOwnProperty(property)
// && source[property] !== null
// && (typeof source[property] === "object" || typeof source[property] === "function")
// && !Object.isFrozen(source[property]))
// deepFreeze(source[property]);
// return source;
// };
export function deepFreeze<T extends Object>(source: T): T {

@@ -36,0 +25,0 @@ Object.freeze(source);

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