Skip to content

Commit

Permalink
resolve #439 resolve #435
Browse files Browse the repository at this point in the history
  • Loading branch information
Guseyn committed Nov 23, 2019
1 parent 4d9546b commit c37acc3
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 112 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,17 @@ Thanks to HTML5 it's possible for relevant browsers. Read further and you'll see

</details>

<details>
<summary><b>updateAttribute</b> (v1.0.2)</summary><br>

You can update an attribute of some element on response:

```html
data-actions-on-response="updateAttribute('#someElmSelector', 'attrName', 'newAttrValue')"
```

</details>

##

You can combine several actions on one response:
Expand Down
257 changes: 157 additions & 100 deletions ehtml.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ehtml.bundle.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions out/actions/ActionByNameWithParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var _require3 = require('./../async-dom/exports'),
ElementWithMappedObject = _require3.ElementWithMappedObject,
ElementsWithToggledClass = _require3.ElementsWithToggledClass,
ElementWithChangedValue = _require3.ElementWithChangedValue,
ElementWithChangedAttribute = _require3.ElementWithChangedAttribute,
ParsedElmSelectors = _require3.ParsedElmSelectors;

var _require4 = require('./../async-log/exports'),
Expand Down Expand Up @@ -153,6 +154,9 @@ var actions = {
},
changeValueOf: function changeValueOf(elmSelector, newValue) {
return new ElementWithChangedValue(new First(new ParsedElmSelectors(elmSelector)), newValue);
},
updateAttribute: function updateAttribute(elmSelector, attrName, attrValue) {
return new ElementWithChangedAttribute(new First(new ParsedElmSelectors(elmSelector)), attrName, attrValue);
}
};

Expand Down
12 changes: 7 additions & 5 deletions out/actions/ParsedActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ function () {
if (typeof param === 'string') {
if (!/\$\{([^${}]+)\}/g.test(param)) {
return param;
} // eslint-disable-next-line no-eval

}

return eval("\n const ".concat(resName, " = resObj\n ").concat(param.replace(/\$\{([^${}]+)\}/g, function (match, p1) {
return p1;
}), "\n "));
return param.replace(/\$\{([^${}]+)\}/g, function (match, p1) {
// eslint-disable-next-line no-eval
return eval("\n const ".concat(resName, " = resObj\n ").concat(match.replace(/^\$\{([^${}]+)\}$/g, function (match, p1) {
return p1;
}), "\n "));
});
}

if (_typeof(param) === 'object') {
Expand Down
48 changes: 48 additions & 0 deletions out/async-dom/ElementWithChangedAttribute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

var _require = require('./../cutie/exports'),
AsyncObject = _require.AsyncObject;

var ElementWithChangedAttribute =
/*#__PURE__*/
function (_AsyncObject) {
_inherits(ElementWithChangedAttribute, _AsyncObject);

function ElementWithChangedAttribute(elm, attrName, attrValue) {
_classCallCheck(this, ElementWithChangedAttribute);

return _possibleConstructorReturn(this, _getPrototypeOf(ElementWithChangedAttribute).call(this, elm, attrName, attrValue));
}

_createClass(ElementWithChangedAttribute, [{
key: "syncCall",
value: function syncCall() {
return function (elm, attrName, attrValue) {
elm.setAttribute(attrName, attrValue);
return elm;
};
}
}]);

return ElementWithChangedAttribute;
}(AsyncObject);

module.exports = ElementWithChangedAttribute;
1 change: 1 addition & 0 deletions out/async-dom/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
DisabledElement: require('./DisabledElement'),
DisabledElements: require('./DisabledElements'),
ElementWithAdditionalHTML: require('./ElementWithAdditionalHTML'),
ElementWithChangedAttribute: require('./ElementWithChangedAttribute'),
ElementWithChangedValue: require('./ElementWithChangedValue'),
ElementWithInnerHTML: require('./ElementWithInnerHTML'),
ElementWithMappedObject: require('./ElementWithMappedObject'),
Expand Down
12 changes: 11 additions & 1 deletion src/actions/ActionByNameWithParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { ResponseFromAjaxRequest, ResponseBody } = require('./../async-ajax/exports')
const { CreatedOptions } = require('./../async-object/exports')
const { ElementWithInnerHTML, ElementWithAdditionalHTML, ElementWithTextContent, HiddenElements, ShownElements, DisabledElements, EnabledElements, ElementWithMappedObject, ElementsWithToggledClass, ElementWithChangedValue, ParsedElmSelectors } = require('./../async-dom/exports')
const { ElementWithInnerHTML, ElementWithAdditionalHTML, ElementWithTextContent, HiddenElements, ShownElements, DisabledElements, EnabledElements, ElementWithMappedObject, ElementsWithToggledClass, ElementWithChangedValue, ElementWithChangedAttribute, ParsedElmSelectors } = require('./../async-dom/exports')
const { Logged } = require('./../async-log/exports')
const { If } = require('./../async-if-else/exports')
const { RedirectedLocation, ReloadedLocation, TurboRedirected } = require('./../async-location/exports')
Expand Down Expand Up @@ -145,6 +145,16 @@ const actions = {
),
newValue
)
},

updateAttribute: (elmSelector, attrName, attrValue) => {
return new ElementWithChangedAttribute(
new First(
new ParsedElmSelectors(elmSelector)
),
attrName,
attrValue
)
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/actions/ParsedActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ class ParsedActions {
if (!/\$\{([^${}]+)\}/g.test(param)) {
return param
}
// eslint-disable-next-line no-eval
return eval(`
const ${resName} = resObj
${param.replace(/\$\{([^${}]+)\}/g, (match, p1) => { return p1 })}
`)
return param.replace(/\$\{([^${}]+)\}/g, (match, p1) => {
// eslint-disable-next-line no-eval
return eval(`
const ${resName} = resObj
${match.replace(/^\$\{([^${}]+)\}$/g, (match, p1) => { return p1 })}
`)
})
}
if (typeof param === 'object') {
for (let key in param) {
Expand Down
18 changes: 18 additions & 0 deletions src/async-dom/ElementWithChangedAttribute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const { AsyncObject } = require('./../cutie/exports')

class ElementWithChangedAttribute extends AsyncObject {
constructor (elm, attrName, attrValue) {
super(elm, attrName, attrValue)
}

syncCall () {
return (elm, attrName, attrValue) => {
elm.setAttribute(attrName, attrValue)
return elm
}
}
}

module.exports = ElementWithChangedAttribute
1 change: 1 addition & 0 deletions src/async-dom/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
DisabledElement: require('./DisabledElement'),
DisabledElements: require('./DisabledElements'),
ElementWithAdditionalHTML: require('./ElementWithAdditionalHTML'),
ElementWithChangedAttribute: require('./ElementWithChangedAttribute'),
ElementWithChangedValue: require('./ElementWithChangedValue'),
ElementWithInnerHTML: require('./ElementWithInnerHTML'),
ElementWithMappedObject: require('./ElementWithMappedObject'),
Expand Down

0 comments on commit c37acc3

Please sign in to comment.