Giter Site home page Giter Site logo

clues's People

Contributors

artikas avatar fijimunkii avatar fzembow avatar jbreckman avatar jpcolomer avatar zjonsson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clues's Issues

solve() with locals doesn't override definitions properly

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

Ability to log errors with `.stack`

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)

Merge the array-style and parameter-style args?

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){
    ...
  }
}

Reptiles server crashes if $global is not passed as an option

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

ES6 function argument regex is too lax

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.

ES6

  • if "function" is a class then solve arguments from the constructor and return a new instance
  • if default values are supplied in function header arguments then make argument optional and replace with default if undefined
  • parse arrow functions, while still restricting access to native functions (i.e. we dont want to expose .pop on an array simply because its on the Array prototype)

[3.0.0-rc1] Circular logic doesn't result in informative error

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.

Support minimization

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.

Optional arguments

An argument with astrix as prefix should be considered optional, i.e. not show an error and set to undefined if missing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.