Skip to content

Commit

Permalink
Disable osmosifying of raw functions
Browse files Browse the repository at this point in the history
There is a "feature" that any function passed as one of properties of
object parameters to any command is replaced with than command. It is
rather inconvenience than handy, because it makes imposible to use
contextCallbacks in set command using object syntax. If setting several
simple properties can be bypassed, by calling set command several times,
using contextCallbacks for nested properties is completely imposible.

It is uncertain what was the reason behind such behaviour. It's hard for
me imagine where sole than command may be usefull in set or any oter
command parameter context. It neither documented, nor covered by tests,
so the proposal is to remove this "feature". This may cause some
regressions in some existing code that relies on such behaviour (is such
code exists), but it will be rather easy to fix by calling then commad
explisitly.

This commit also fixes #203 as `type: () => "some string"` now works.
  • Loading branch information
samogot committed Nov 13, 2018
1 parent 5bf419b commit 984bd2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,6 @@ Command.prototype.findCommandArg = function (obj) {
}

break;
case 'function':
obj[key] = this.findCommandArg(this.then(obj[key]));
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ var osmosis = require('../index'),
{ url: '/1', link: 1 },
{ url: '/2', link: 2 }
],
links_count: 2,
const_value: "not a selector",
page2: { title: 2 }
},
url = server.host + ':' + server.port;
Expand Down Expand Up @@ -104,6 +106,12 @@ module.exports.callbacks = function (assert) {
.set('url', function (link) {
return link.getAttribute("href");
}),
links_count: function (context) {
return context.find("a").length;
},
const_value: function (context) {
return "not a selector";
},
page2: osmosis.get(function (doc) {
return doc.querySelector('a:last');
}).set('title', 'title')
Expand Down

0 comments on commit 984bd2c

Please sign in to comment.