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

melody-runtime

Package Overview
Dependencies
Maintainers
3
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

melody-runtime - npm Package Compare versions

Comparing version 1.2.0-commit.05c42290 to 1.2.0-commit.088eeea3

src/async.js

115

lib/index.esm.js

@@ -13,2 +13,3 @@ import _isString from 'lodash/isString';

import _isNumber from 'lodash/isNumber';
import { enqueueComponent, link } from 'melody-idom';

@@ -894,2 +895,114 @@ /**

var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var AsyncComponent = function () {
function AsyncComponent() {
classCallCheck(this, AsyncComponent);
this.promisedComponent = null;
this._el = null;
this.refs = Object.create(null);
this.props = null;
this.resolvedComponent = null;
this.alreadyUnmounted = false;
this.isLoading = false;
this.loadingError = null;
}
AsyncComponent.prototype.apply = function apply(props) {
var _this = this;
this.props = props;
var promisedComponent = props.promisedComponent;
// if we already have resolved the component, just pass the data forward
if (this.resolvedComponent) {
this.resolvedComponent.apply(this.props.data);
}
// otherwise
if (!this.isLoading) {
this.isLoading = true;
promisedComponent().then(function (_ref) {
var Component = _ref.default;
if (_this.alreadyUnmounted) {
return;
}
_this.resolvedComponent = new Component();
link(_this, _this.resolvedComponent);
_this.resolvedComponent.el = _this._el;
_this.resolvedComponent.apply(_this.props.data);
}, function (err) {
// fail early
_this.loadingError = err;
enqueueComponent(_this);
}).catch(function (err) {
// just in case something went wrong while initialising the component
_this.loadingError = err;
enqueueComponent(_this);
});
if (this.props.delayLoadingAnimation) {
setTimeout(function () {
return enqueueComponent(_this);
}, this.props.delayLoadingAnimation);
} else {
enqueueComponent(this);
}
}
};
AsyncComponent.prototype.notify = function notify() {};
AsyncComponent.prototype.componentWillUnmount = function componentWillUnmount() {
this.alreadyUnmounted = true;
};
AsyncComponent.prototype.render = function render() {
if (!this.resolvedComponent) {
if (this.loadingError && this.props.onError) {
this.props.onError(this.loadingError);
} else {
this.props.whileLoading();
}
}
};
createClass(AsyncComponent, [{
key: 'el',
set: function set$$1(el) {
if (this.resolvedComponent) {
this.resolvedComponent.el = el;
}
this._el = el;
return el;
},
get: function get$$1() {
return this.resolvedComponent ? this.resolvedComponent.el : this._el;
}
}]);
return AsyncComponent;
}();
/**

@@ -911,2 +1024,2 @@ * Copyright 2017 trivago N.V.

export { createSubContext, batch, attrs, styles, classes, merge, replace, reverse, round, striptags, number_format, format, title, url_encode, strtotime, trim, random, min, max, cycle, attribute, isEmpty, inheritBlocks };
export { AsyncComponent, createSubContext, batch, attrs, styles, classes, merge, replace, reverse, round, striptags, number_format, format, title, url_encode, strtotime, trim, random, min, max, cycle, attribute, isEmpty, inheritBlocks };

@@ -19,2 +19,3 @@ 'use strict';

var _isNumber = _interopDefault(require('lodash/isNumber'));
var melodyIdom = require('melody-idom');

@@ -900,2 +901,114 @@ /**

var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var AsyncComponent = function () {
function AsyncComponent() {
classCallCheck(this, AsyncComponent);
this.promisedComponent = null;
this._el = null;
this.refs = Object.create(null);
this.props = null;
this.resolvedComponent = null;
this.alreadyUnmounted = false;
this.isLoading = false;
this.loadingError = null;
}
AsyncComponent.prototype.apply = function apply(props) {
var _this = this;
this.props = props;
var promisedComponent = props.promisedComponent;
// if we already have resolved the component, just pass the data forward
if (this.resolvedComponent) {
this.resolvedComponent.apply(this.props.data);
}
// otherwise
if (!this.isLoading) {
this.isLoading = true;
promisedComponent().then(function (_ref) {
var Component = _ref.default;
if (_this.alreadyUnmounted) {
return;
}
_this.resolvedComponent = new Component();
melodyIdom.link(_this, _this.resolvedComponent);
_this.resolvedComponent.el = _this._el;
_this.resolvedComponent.apply(_this.props.data);
}, function (err) {
// fail early
_this.loadingError = err;
melodyIdom.enqueueComponent(_this);
}).catch(function (err) {
// just in case something went wrong while initialising the component
_this.loadingError = err;
melodyIdom.enqueueComponent(_this);
});
if (this.props.delayLoadingAnimation) {
setTimeout(function () {
return melodyIdom.enqueueComponent(_this);
}, this.props.delayLoadingAnimation);
} else {
melodyIdom.enqueueComponent(this);
}
}
};
AsyncComponent.prototype.notify = function notify() {};
AsyncComponent.prototype.componentWillUnmount = function componentWillUnmount() {
this.alreadyUnmounted = true;
};
AsyncComponent.prototype.render = function render() {
if (!this.resolvedComponent) {
if (this.loadingError && this.props.onError) {
this.props.onError(this.loadingError);
} else {
this.props.whileLoading();
}
}
};
createClass(AsyncComponent, [{
key: 'el',
set: function set$$1(el) {
if (this.resolvedComponent) {
this.resolvedComponent.el = el;
}
this._el = el;
return el;
},
get: function get$$1() {
return this.resolvedComponent ? this.resolvedComponent.el : this._el;
}
}]);
return AsyncComponent;
}();
/**

@@ -917,2 +1030,3 @@ * Copyright 2017 trivago N.V.

exports.AsyncComponent = AsyncComponent;
exports.createSubContext = createSubContext;

@@ -919,0 +1033,0 @@ exports.batch = batch;

5

package.json
{
"name": "melody-runtime",
"version": "1.2.0-commit.05c42290",
"version": "1.2.0-commit.088eeea3",
"description": "",

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

},
"peerDependencies": {
"melody-idom": "^1.2.0"
},
"devDependencies": {

@@ -17,0 +20,0 @@ "rollup-plugin-babel": "^2.6.1"

@@ -488,3 +488,3 @@ /**

// Plain Math.round doesn't just truncate
number = Math.round(number - number % 1);
number = Math.round(number - (number % 1));
prefix = number < 0 ? '-' : positivePrefix;

@@ -491,0 +491,0 @@ value =

@@ -36,1 +36,4 @@ /**

export { isEmpty, inheritBlocks } from './helpers';
import AsyncComponent from './async';
export { AsyncComponent };
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