zjonsson / clues Goto Github PK
View Code? Open in Web Editor NEWLogical framework for complex asynchronous structures (uses promises)
License: Other
Logical framework for complex asynchronous structures (uses promises)
License: Other
This is in [email protected], not sure if it is expected behavior, but I found it surprising.
Run the following:
var clues = require('clues');
var api = {
A: function(B){
return B;
},
B: function(C){
return C;
},
}
var facts = {};
var locals = {B: 42};
var solver = new clues(api, facts);
solver.solve(api.A, locals)
.then(function(result){
console.log("result", result);
})
.catch(function(error){
console.log("error", error);
});
The result is an error complaining that C not defined
. But I've overridden the definition of B
, and we should never be solving for C.
If I set
facts = {B: 42};
locals = {B: 13};
Then the result I get is 42. So it seems that using locals
is broken and directly contradicts the documentation:
The second argument (optional) allows local variables that will be used, and have priority, against facts and logic
var obj = {
b: () => {
throw new Error("sample");
},
c: b => b,
d: c => c,
e: d => d
}
clues(obj, 'e', { $logError: console.error } );
Will log the Error
4 times
Arguments are fetched by splitting on commas, and can therefore include spaces.
Logging errors at the response level (i.e. reptiles) might not be enough as any errored function might be an optional argument - in which case the error never reaches the final response.
Todo: add catch right after fn.apply that send the error to $global.$logError (optional)
Consider the following:
var clues = require("clues");
var logic = {
user: {
name: "Meow Zedong",
},
answer: 42,
message: ['user.name', function(name, answer) {
return name + ", the answer is: " + answer;
}]
};
clues(logic, 'message').then(function(res){
console.log(res);
});
This results in:
Meow Zedong, the answer is: undefined
Obviously this will work as we expect if the array-style arguments also include answer
... but do you think that the positional arguments in the array could be extended by the arguments in the function?
I found that when using reptiles with some user input I end up seeing something like
var api = {
something: ['input.A', 'B', 'C', 'D', 'E', function(a, b, c, d, e){
...
}
}
... and it feels very verbose when it's just the first variable that needs the object resolution. Would be much nicer if it were:
var api = {
something: ['input.A', function(a, b, c, d, e){
...
}
}
Parse the async keyword in the function signature to allow async
await
Can parse argument names from..
something: function(alpha, beta, gamma, delta) {
return true;
},
Fails to parse when there are line breaks:
something: function(
alpha,
beta,
gamma,
delta
) {
return true;
},
Note that the original reporter was on a PC so perhaps its to do with the other style of line breaks
After the latest update added the ability to pass $duration
, the reptiles server will crash if $global
is not passed as an option to clues:
TypeError: Cannot read property '$duration' of undefined at ../node_modules/clues/util/reptiles-server.js:104:42
Adding a blank $global: {}
to the reptiles parameters fixes the issue i.e. reptiles(api, { debug:true, stringify: require('./lib/stringify'), $global: {}}));
Caused by https://github.com/ZJONSSON/clues/blob/master/util/reptiles-server.js#L104
Upgrade the promise library to use bluebird as default, given high performance.
class Something {
function(_detail,
_detailᐅa,
_detailᐅb) {
return _detail + _detailᐅa + _detailᐅb;
}
}
This will not solve for detail
correctly.
Currently, var reEs6 = /^\s*\({0,1}(.*?)\){0,1}\s*=>/;
will match the following function:
main(_prioritize,a,b,c) { return (a,b) => 5; }
It will NOT match:
main(_prioritize,a,b,c) { return 5; }
The main problem is that the one expression wanted to handle things with or without parenthesis.
So it tries to match (a,b) => { ... }
as well as b => { ... }
. Unfortunately, this allows for es6 class methods to match the beginning aspect, and as long as there is a =>
somewhere inside the function (maybe only on the same line?), this matches.
This regular expression should be ^\s*\({0,1}([^)]*?)\){0,1}\s*=>
. There is no way an argument can contain a )
, so we can just read things until we hit the end of that.
Similar to reptiles-server, but should resolve requests generated by Falcor
Netflix/falcor-router#117
undefined
.pop
on an array simply because its on the Array prototype)STEPS
Run the following logic:
var logic = {
A: function(B) {
return B;
},
B: function(A) {
return A;
}
};
clues(logic, 'A');
RESULT
It throws an error, but it's uninformative:
/Users/fzembow/git/clues/clues.js:63
.map(function(arg) {
^
RangeError: Maximum call stack size exceeded
EXPECTED
An error like "Circular dependency detected" or ideally "Circular dependency detected between A, B"
I ran into this when building something and it was rather annoying to trace down exactly what was happening. Let's talk through how we can address this.
Implement an angular type version of function definitions where (optionally) an api function can be defined as array, with variable-names in the front and the actual function as last element of the array.
An argument with astrix as prefix should be considered optional, i.e. not show an error and set to undefined if missing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.