var test = require('tap').test var wrappy = require('../wrappy.js') test('basic', function (t) { function onceifier (cb) { var called = false return function () { if (called) return called = true return cb.apply(this, arguments) } } onceifier.iAmOnce = {} var once = wrappy(onceifier) t.equal(once.iAmOnce, onceifier.iAmOnce) var called = 0 function boo () { t.equal(called, 0) called++ } // has some rando property boo.iAmBoo = true var onlyPrintOnce = once(boo) onlyPrintOnce() // prints 'boo' onlyPrintOnce() // does nothing t.equal(called, 1) // random property is retained! t.equal(onlyPrintOnce.iAmBoo, true) var logs = [] var logwrap = wrappy(function (msg, cb) { logs.push(msg + ' wrapping cb') return function () { logs.push(msg + ' before cb') var ret = cb.apply(this, arguments) logs.push(msg + ' after cb') } }) var c = logwrap('foo', function () { t.same(logs, [ 'foo wrapping cb', 'foo before cb' ]) }) c() t.same(logs, [ 'foo wrapping cb', 'foo before cb', 'foo after cb' ]) t.end() })
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19553 | swellard | Move and rename clients | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/javascript/node_modules/wrappy/test/basic.js | |||||
#1 | 18810 | tjuricek |
First-pass at JavaScript client SDK. JavaScript requires Node with Gulp to "browserfy" the library. It's the easiest way I found to use the swagger-js project; bundle up a wrapping method. There is no JavaScript reference guide. The swagger-js doesn't really document what they do very well, actually. Overall I'm not particularly impressed by swagger-js, it was hard to even figure out what the right method syntax was. We may want to invest time in doing it better. This required setting CORS response headers, which are currently defaulted to a fairly insecure setting. |