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

monkberry

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

monkberry - npm Package Compare versions

Comparing version 3.7.2 to 3.7.3

CHANGELOG.md

53

lib/compiler/attribute.js

@@ -10,14 +10,10 @@ 'use strict';

exports.default = function (ast) {
/**
* Compile attributes of regular nodes.
* @param {Figure} figure
* @param {string} nodeName
*/
ast.AttributeNode.prototype.compile = function (figure, nodeName) {
var _this = this;
// Transform attribute with text and expression into single expression.
//
// <div class="cat {{ dog }} {{ cow }}">
//
// Will transformed into:
//
// <div class={{ 'cat ' + dog + ' ' + cow }}>
//
var _compileToExpression = this.compileToExpression();

@@ -48,4 +44,5 @@

//
// On other side, if one of expression contains default value,
// Monkberry will set attribute for every variable:
// TODO: Implement updater, if one of expression contains default value.
// Example (now this does not work):
//

@@ -59,4 +56,2 @@ // <div class="{{ foo }} {{ bar || 'default' }}">

// TODO: Implement other side.
figure.addUpdater(this.loc, variables, function () {

@@ -91,2 +86,10 @@ return (0, _sourceNode.sourceNode)(_this.loc, [' ', attr(_this.loc, nodeName, _this.name, expr.compile())]);

/**
* Generate source nodes for attribute.
* @param {Object} loc
* @param {string} nodeName
* @param {string} attrName
* @param {string} value
* @returns {SourceNode}
*/
function attr(loc, nodeName, attrName, value) {

@@ -100,2 +103,7 @@ if (plainAttributes.indexOf(attrName) != -1) {

/**
* Returns default value for attribute name.
* @param {string} attrName
* @returns {string}
*/
function defaultAttrValue(attrName) {

@@ -109,2 +117,15 @@ if (booleanAttributes.indexOf(attrName) != -1) {

/**
* Transform attribute with text and expression into single expression.
*
* <div class="cat {{ dog }} {{ cow || 'moo' }}">
*
* Will transformed into:
*
* <div class={{ 'cat ' + dog + ' ' + (cow || 'moo') }}>
*
* Also collects default values for attribute: `cat ` and variables name with default: ['moo'].
*
* @returns {*[]}
*/
ast.AttributeNode.prototype.compileToExpression = function () {

@@ -127,4 +148,2 @@ var expr,

defaults.push(node.expression.right.compile());
// TODO: Implement other side.
}

@@ -156,2 +175,6 @@ }

/**
* @param {Object} node
* @returns {Object}
*/
function extract(node) {

@@ -158,0 +181,0 @@ if (node.type == 'ExpressionStatement') {

@@ -135,3 +135,3 @@ 'use strict';

parts.push((0, _sourceNode.sourceNode)(loc, [' λ.', functionName, '(__data__, ', params.map(function (param) {
parts.push((0, _sourceNode.sourceNode)(loc, [' λ__', functionName, '(__data__, ', params.map(function (param) {
return '__cache__.' + param;

@@ -138,0 +138,0 @@ }).join(', '), ');']));

@@ -62,3 +62,3 @@ 'use strict';

if ((0, _utils.size)(this.complexUpdaters) > 0) {
sn.add(' // Complex update functions\n').add(' var __cache__ = view.__cache__ = {};\n').add(' var λ = {\n').add([this.compileComplexUpdaters(), '\n']).add(' };\n').add('\n');
sn.add(' // Complex update functions\n').add(' var __cache__ = view.__cache__ = {};\n').add(' var ').add([this.compileComplexUpdaters(), ';\n']).add('\n');
}

@@ -120,6 +120,6 @@

Object.keys(this.complexUpdaters).forEach(function (key) {
parts.push((0, _sourceNode.join)([' ', key, ': ', _this2.complexUpdaters[key].compile()]));
parts.push((0, _sourceNode.join)(['λ__', key, ' = ', _this2.complexUpdaters[key].compile()]));
});
return (0, _sourceNode.sourceNode)(null, parts).join(',\n');
return (0, _sourceNode.sourceNode)(null, parts).join(',\n ');
}

@@ -126,0 +126,0 @@ }, {

@@ -0,1 +1,8 @@

/** _ _
* /\/\ ___ _ __ | | _| |__ ___ _ __ _ __ _ _
* / \ / _ \| '_ \| |/ / '_ \ / _ \ '__| '__| | | |
* / /\/\ \ (_) | | | | <| |_) | __/ | | | | |_| |
* \/ \/\___/|_| |_|_|\_\_.__/ \___|_| |_| \__, |
* |___/
*/
(function (document) {

@@ -13,5 +20,16 @@ /**

/**
* Main loops processor.
* @param {Monkberry.View} parent - Parent view, where to place loop elements.
* @param {Element} node - Parent element, where to append child. Note what it can be a comment element.
* @param {Map} map - Map contains views from previous loop render.
* @param {string} template - Template name to render.
* @param {*} data - Data object passed into view.update() function.
* @param {*} array - Data iterating on.
* @param {object} options - Loop options, value and key names.
*/
Monkberry.prototype.foreach = function (parent, node, map, template, data, array, options) {
var i, j, len, keys, transform, arrayLength, childrenSize = map.length;
// Get array length, and convert object ot array, if needed.
if (Array.isArray(array)) {

@@ -26,2 +44,3 @@ transform = transformArray;

// In new array contains less items what before, remove surpluses.
len = childrenSize - arrayLength;

@@ -36,2 +55,3 @@ for (i in map.items) {

// If there is already some views, update there data with new.
j = 0;

@@ -43,2 +63,3 @@ for (i in map.items) {

// If new array contains more items when previous, render new views and append them.
for (j = childrenSize, len = arrayLength; j < len; j++) {

@@ -77,4 +98,14 @@ // Render new view.

/**
* Main if/else, custom tags, blocks processor.
* @param {Monkberry.View} parent - Parent view, where to place loop elements.
* @param {Element} node - Parent element, where to append child. Note what it can be a comment element.
* @param {{ref:object}} child - Object which may contains previous rendered view.
* @param {string} template - Template name to render.
* @param {*} data - Data object passed into view.update() function.
* @param {boolean} test - Whenever to insert then view.
* @returns {boolean} Returns test value.
*/
Monkberry.prototype.insert = function (parent, node, child/*.ref*/, template, data, test) {
if (child.ref) {
if (child.ref) { // If view was already inserted, update or remove it.
if (test) {

@@ -81,0 +112,0 @@ child.ref.update(data);

{
"name": "monkberry",
"version": "3.7.2",
"version": "3.7.3",
"description": "JavaScript DOM Template Engine",

@@ -39,3 +39,2 @@ "bin": "bin/monkberry",

"babel-cli": "^6.4.0",
"babel-plugin-transform-flow-strip-types": "^6.4.0",
"babel-preset-es2015": "^6.3.13",

@@ -42,0 +41,0 @@ "doctoc": "^0.15.0",

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