Coder Social home page Coder Social logo

Comments (5)

tsachis avatar tsachis commented on June 9, 2024 1

With the above solution, it will be hard to define many different states for a single url and control them from the UI\API, which is what Leonardo is all about.

I suggest we add a new match property on the state level - which is a function that gets the request and returns a boolean which determine if Leonardo should use this state or keep looking for other matching states.
It will enable defining many states with the same URL and different macth function.

example:

Leonardo.addState({
        name: 'Get Comments',
        verb: 'GET',
        url: 'api/comments',
        match: (request) => {
           // returns true is this request should be processed by the current state, 
           // otherwise Leonardo will keep looking for matching state
           return !!request.body.comments;
        },
        options: [{
            "name": "Success with function",
            "status": 200,
            "data": {
				comments: {}
			}
		]}
    })

@dwido WDYT?

from leonardo.

dwido avatar dwido commented on June 9, 2024

hey @k3nsei,
Thanks for bringing this up, I am thinking of a few ways to deal with this when data property is a function

  1. when returning undefined from the function it will pass to the server
  2. returning a global e.g.
    Leonardo.addState({
        name: 'Get Comments',
        verb: 'GET',
        url: 'api/comments',
        options: [{
            "name": "Success with function",
            "status": 200,
            "data": (request) => {
               // calculate response in real time
               return Leonardo.goToServer;
        }]
    }

@tsachis @MrFrankel any other ideas?

from leonardo.

k3nsei avatar k3nsei commented on June 9, 2024

I think that @tsachis approach is quite good.

from leonardo.

dwido avatar dwido commented on June 9, 2024

@tsachis seems that this approach is problematic when working with Sinon, the reason is that the decision if to mock a state or let it pass through is done when the xhr.open method is being called when there are no parameters of the request

from leonardo.

david2tm avatar david2tm commented on June 9, 2024

@tsachis this can be closed

from leonardo.

Related Issues (20)

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.