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

sling-web-framework

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sling-web-framework - npm Package Compare versions

Comparing version 0.15.1 to 0.16.0

src/v1/src/basic/SlingElement.js

7

package.json
{
"name": "sling-web-framework",
"version": "0.15.1",
"version": "0.16.0",
"description": "",

@@ -12,5 +12,6 @@ "main": "dist/cjs/index.js",

"dependencies": {
"sling-web-helpers": "^0.15.1",
"sling-web-sdk": "^0.15.1"
"sling-web-helpers": "^0.16.0",
"sling-web-sdk": "^0.16.0",
"sling-web-storage": "^0.16.0"
}
}

@@ -11,4 +11,2 @@ import { globalHelper } from '../../node_modules/sling-web-helpers/src/index.js';

this.lastRequestParams = {};
this.requiredParamNames = Object.keys(
this.constructor._observedRequiredRequestParams);
}

@@ -60,9 +58,4 @@

const { properties = {} } = this.constructor;
const sdkTriggering = Object
.entries(properties)
.filter(([, value]) => value.callSdk)
.map(([key]) => key);
const { _observedRequestParams } = this.constructor;
const sdkTriggering = Object.keys(_observedRequestParams);
const changedProps = Object.keys(changes || {});

@@ -76,3 +69,3 @@

_shouldTriggerSdkCall() {
get _shouldTriggerSdkCall() {
const { requestParams = {}, lastRequestParams = {} } = this;

@@ -103,3 +96,4 @@ const requestKeys = Object.keys(requestParams);

.reduce((result, obj) => ({ ...result, ...obj }), {});
if (this._shouldTriggerSdkCall()) {
if (this._shouldTriggerSdkCall) {
if (globalHelper.isFunction(this.getdata)) {

@@ -106,0 +100,0 @@ this.getdata(this.requestParams, this.instance);

@@ -0,30 +1,34 @@

import sinon from 'sinon';
import { withBusinessLogic } from './withBusinessLogic.js';
import { domHelper } from '../../node_modules/sling-web-helpers/src/index.js';
import { LitElement } from '../lib/lit-element.bundle.js';
describe('withBusinessLogic', () => {
class BusinessLogicLitElement extends withBusinessLogic(LitElement) {
static get properties() {
return {
required: {
callSdk: 'required',
},
anotherRequired: {
callSdk: 'required',
},
optional: {
callSdk: 'optional',
},
};
}
let $dummy;
let spy;
render() {}
class BusinessTester extends withBusinessLogic() {
static get properties() {
return {
token: {
callSdk: 'required',
},
id: {
callSdk: 'required',
},
state: {
callSdk: 'optional',
},
loading: {
type: Boolean,
},
};
}
domHelper.registerComponent('business-logic-lit', BusinessLogicLitElement);
render() {}
}
let $dummy;
window.customElements.define('business-tester', BusinessTester);
describe('withBusinessLogic', () => {
beforeEach(() => {
$dummy = document.createElement('business-logic-lit');
spy = sinon.spy();
$dummy = document.createElement('business-tester');
document.body.appendChild($dummy);

@@ -36,36 +40,150 @@ });

$dummy = null;
spy = null;
});
it('_shouldTriggerSdkCall should return false if all required properties ' +
'are falsey and the last request is different from the current.', () => {
$dummy.requestParams = { a: 1 };
$dummy.lastRequestParams = { a: 2 };
expect($dummy._shouldTriggerSdkCall()).to.equal(false);
describe('#_observedRequestParams', () => {
it('Should observe some properties that are either required ' +
'or optional to make requests.', () => {
expect($dummy.constructor._observedRequestParams)
.to.eql({
token: {
callSdk: 'required',
},
id: {
callSdk: 'required',
},
state: {
callSdk: 'optional',
},
});
});
});
it('_shouldTriggerSdkCall should return false if any required properties ' +
'are falsey and the last request is different from the current.', () => {
$dummy.requestParams = { a: 1 };
$dummy.lastRequestParams = { a: 2 };
$dummy.required = 'required';
expect($dummy._shouldTriggerSdkCall()).to.equal(false);
describe('#_observedRequiredRequestParams', () => {
it('Should observe some properties that are required ' +
'to make requests.', () => {
expect($dummy.constructor._observedRequiredRequestParams)
.to.eql({
token: {
callSdk: 'required',
},
id: {
callSdk: 'required',
},
});
});
});
it('_shouldTriggerSdkCall should return true if all required properties ' +
'are truthy and the last request is different from the current.', () => {
$dummy.requestParams = { a: 1 };
$dummy.lastRequestParams = { a: 2 };
$dummy.required = 'required';
$dummy.anotherRequired = 'required';
expect($dummy._shouldTriggerSdkCall()).to.equal(true);
describe('._propertiesChanged', () => {
it('Should run _triggerSdkCall if a required ' +
'parameter changes.', (done) => {
$dummy._triggerSdkCall = spy;
expect(spy).not.to.have.been.called;
$dummy.token = '111222333444';
setTimeout(() => {
expect(spy).to.have.been.calledOnce;
done();
});
});
it('Should run _triggerSdkCall if an optional ' +
'parameter changes.', (done) => {
$dummy._triggerSdkCall = spy;
expect(spy).not.to.have.been.called;
$dummy.state = 'level';
setTimeout(() => {
expect(spy).to.have.been.calledOnce;
done();
});
});
it('Should not run _triggerSdkCall if an unrelated ' +
'property changes.', (done) => {
$dummy._triggerSdkCall = spy;
expect(spy).not.to.have.been.called;
$dummy.loading = true;
setTimeout(() => {
expect(spy).not.to.have.been.called;
done();
});
});
});
it('_shouldTriggerSdkCall should return false if all required properties ' +
'are truthy but the last request is equal to the current.', () => {
$dummy.requestParams = { a: 1 };
$dummy.lastRequestParams = { a: 1 };
$dummy.required = 'required';
$dummy.anotherRequired = 'required';
expect($dummy._shouldTriggerSdkCall()).to.equal(false);
describe('._shouldTriggerSdkCall', () => {
it('Should return true if the last request was made with ' +
'different parameters and all required ones are present.', () => {
$dummy.token = '111222333444';
$dummy.id = '12345';
$dummy.requestParams = {
token: $dummy.token,
id: $dummy.id,
};
$dummy.lastRequestParams = {};
expect($dummy._shouldTriggerSdkCall).to.be.true;
});
it('Should return true if an optional parameter is added.', () => {
$dummy.token = '111222333444';
$dummy.id = '12345';
$dummy.requestParams = {
token: $dummy.token,
id: $dummy.id,
};
$dummy.lastRequestParams = {
...$dummy.requestParams,
};
expect($dummy._shouldTriggerSdkCall).to.be.false;
$dummy.state = '12345';
$dummy.lastRequestParams = { ...$dummy.requestParams };
$dummy.requestParams = {
token: $dummy.token,
id: $dummy.id,
state: $dummy.state,
};
expect($dummy._shouldTriggerSdkCall).to.be.true;
});
it('Should return false if the last request has been made ' +
'with the same parameters.', () => {
$dummy.token = '111222333444';
$dummy.id = '12345';
$dummy.requestParams = {
token: $dummy.token,
id: $dummy.id,
};
$dummy.lastRequestParams = {
...$dummy.requestParams,
};
expect($dummy._shouldTriggerSdkCall).to.be.false;
});
it('Should return false if the request is missing ' +
'required parameters.', () => {
$dummy.token = '111222333444';
$dummy.requestParams = {
token: $dummy.token,
};
$dummy.lastRequestParams = {};
expect($dummy._shouldTriggerSdkCall).to.be.false;
});
});
});

@@ -7,3 +7,4 @@ import { globalHelper } from '../../node_modules/sling-web-helpers/src/index.js';

static get _initializedProperties() {
return globalHelper.pickBy(this.properties, ({ value }) => value != null);
return globalHelper.pickBy(this.properties || {}
, ({ value }) => value != null);
}

@@ -10,0 +11,0 @@

@@ -7,3 +7,3 @@ import { globalHelper } from '../../node_modules/sling-web-helpers/src/index.js';

static get _observedProperties() {
return globalHelper.pickBy(this.properties,
return globalHelper.pickBy(this.properties || {},
({ observer }) => observer != null);

@@ -10,0 +10,0 @@ }

@@ -7,3 +7,3 @@ import { globalHelper } from '../../node_modules/sling-web-helpers/src/index.js';

static get _reflectedProperties() {
return globalHelper.pickBy(this.properties,
return globalHelper.pickBy(this.properties || {},
({ reflectToAttribute }) => reflectToAttribute);

@@ -10,0 +10,0 @@ }

import { html } from './lib/lit-element.bundle.js';
import { svg } from './lib/lit-extended.bundle.js';
import { SlingElement } from './framework/SlingElement.js';

@@ -10,3 +9,2 @@ import { SlingBusinessElement } from './framework/SlingBusinessElement.js';

html,
svg,
};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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