8.1.0 • Published 7 years ago

path-event v8.1.0

Weekly downloads
10
License
Apache-2.0
Repository
github
Last release
7 years ago

PathEvent Build Status Coverage Status

The PathEvent class, which inherits from y-lock, contains the logic behind the ending asterisk path strategy. Think of the event flow as an assembly line: when each listener is done with the event, it forwards it to the next one, until one of it decides that the event is fully handled and stops the flow.

Let's suppose our path is /what/an/example/this/is. With this example, the following events will be emitted, one after another:

/what/an/example/this/is
/what/an/example/this/*
/what/an/example/*
/what/an/*
/what/*
/*

As you can see, all flows start with the original path. The flow continues until the /* event is reached. Prefixes are allowed, e.g if you were using hsm and a POST request was what originated the event, the flow would be the following:

POST /what/an/example/this/is
/what/an/example/this/is
POST /what/an/example/this/*
/what/an/example/this/*
POST /what/an/example/*
/what/an/example/*
POST /what/an/*
/what/an/*
POST /what/*
/what/*
POST /*
/*

Each event object inherits from event.common which is the original PathEvent instance. event.args contains the rest of the path, e.g an/example/this/is. event.argv(n) returns an array of length n with each decoded component of the path. Take a look at the following example:

target.on('/animals/dogs/*',function*(e){
  var breed = e.argv(1)[0];

  yield e.take();
  if(breed == 'chihuahua'){

    e.give();  // Ignore chihuahuas
    yield e.take();   // If everyone else ignores it,
                      // take it back

    console.log('nobody likes this one!');
    return;
  }

  console.log('got a dog!');

});

target.on('/animals/*',function(e){
  var colour = e.argv(3)[2];

  yield e.take();
  if(colour == 'black'){
    e.give();  // I can't see black animals
    return;
  }

  console.log('got an animal!');

});

Consider these three events:

  • /animals/dogs/husky/black
  • /animals/dogs/chihuahua/white
  • /animals/dogs/chihuahua/black

The console output of those three events would be, respectively:

  • got a dog!
  • got an animal!
  • nobody likes this one!
8.1.0

7 years ago

8.0.0

7 years ago

7.0.1

7 years ago

7.0.0

7 years ago

6.1.2

7 years ago

6.1.1

7 years ago

6.1.0

8 years ago

6.0.3

8 years ago

6.0.2

8 years ago

6.0.1

8 years ago

6.0.0

8 years ago

5.2.2

8 years ago

5.2.1

8 years ago

5.2.0

8 years ago

5.1.1

8 years ago

5.1.0

8 years ago

5.0.0

8 years ago

4.0.0

8 years ago

3.1.6

9 years ago

3.1.5

9 years ago

3.1.4

9 years ago

3.1.3

9 years ago

3.1.2

9 years ago

3.1.1

9 years ago

3.1.0

9 years ago

3.0.3

9 years ago

3.0.2

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.0.1

9 years ago

0.0.0

9 years ago