Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[minor] minor style and comment changes

  • Loading branch information...
commit 81dedb952065e64186810f77ac04f072f174dd74 1 parent 85d1045
Nuno Job authored

Showing 1 changed file with 9 additions and 11 deletions. Show diff stats Hide diff stats

  1. 20  pattern.js
20  pattern.js
... ...
@@ -1,18 +1,17 @@
1 1
 (function () { // stack refers to registered patterns
2 2
   var DEBUG = typeof process !== 'undefined' && process.env.DEBUG;
3 3
   function log() { if(DEBUG) console.log.apply(this,arguments); }
4  
-  function match(pattern, value) {
5  
-    if(pattern === Error) { 
6  
-      return value && value.name.indexOf('Error') !== -1;}
  4
+  function match(pattern, val) {
  5
+    if(pattern === Error) { return val && val.name.indexOf('Error') !== -1; }
7 6
     if(pattern === undefined) return true;
8 7
     if(typeof pattern === 'object')
9  
-      return JSON.stringify(pattern) === JSON.stringify(value);
10  
-    return pattern.toString() === value.toString(); }
11  
-  function p() { var stack = [], arity;
  8
+      return JSON.stringify(pattern) === JSON.stringify(val);
  9
+    return pattern.toString() === val.toString(); }
  10
+  function p() { var stack = [], arity; // stack keeps stack of patterns
12 11
     return function () {
13 12
     if(!arity) { arity = arguments.length-1; } // set arity in first invok.
14 13
     if(arity===arguments.length) { // # arguments match arity, execute
15  
-      var j = 0, i=0; // we need explicit control over vars
  14
+      var j=0, i=0; // we need explicit control over vars
16 15
       ol: for(; i<arguments.length; i++) { // for each argument
17 16
         il: for(; j<stack.length; j++) { // for pattern in the stack
18 17
           var s = stack[j]; // get the current pattern
@@ -22,21 +21,20 @@
22 21
           log('  • ', [].slice.call(arguments,0));
23 22
           if(s.length > i) { // if there's something in this pos for pattern
24 23
             if(match(s[i], arguments[i])) { // if we have a match
25  
-              log('  ✔ ', s[i], '===', arguments[i]);
  24
+              log('  ✔ ', s[i], '===', arguments[i]); // not last v in patt?
26 25
               if(arguments.length !== i+1) { log('  ⥁'); continue ol; } }
27 26
             else {  // if it doesnt match try next pattern in stack
28 27
               log('  ✗ ', s[i], '===', arguments[i]);
29 28
               i=0;
30  
-              // dont break and set ok to false if this is the last element
31 29
               if(stack.length!==j+1) { log('  ⥁'); continue; } } }
32 30
          var f = s[s.length-1];
33 31
          log('  ' + (typeof f === 'function' ? 'ƒ' : 'λ'), f.name || f);
34 32
          // execute whatever is the last argument on last pattern of stack
35 33
          return (typeof f === 'function') ? // is there a callback?
36  
-           f.apply(this, [].slice.call(arguments,0)) : null; } }
  34
+           f.apply(this, arguments) : null; } }
37 35
     } else {
38 36
       stack.push([].slice.call(arguments,0)); // initializing add pattern
39 37
       log('‣ ', [].slice.call(arguments,0));
40  
-    } }; } // dont cache, each require is a new inst.
  38
+    } }; }
41 39
   typeof exports === 'undefined' ? (window.pattern=p) : (module.exports = p);
42 40
 })();

0 notes on commit 81dedb9

Please sign in to comment.
Something went wrong with that request. Please try again.