forked from tradle/react-native-udp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from tradle/master
feat(update): merge fixes
- Loading branch information
Showing
7 changed files
with
114 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = function normalizeBindOptions(...args) { | ||
const [arg1, arg2] = args | ||
const lastArg = args[args.length - 1] | ||
let options = {} | ||
|
||
if (typeof arg1 === 'object') { | ||
options = arg1 | ||
} else if (typeof arg1 === 'number') { | ||
options.port = arg1 | ||
} else if (typeof arg1 === 'string') { | ||
options.address = arg1 | ||
} | ||
if (typeof arg2 === 'string') { | ||
options.address = arg2 | ||
} | ||
if (typeof lastArg === 'function') { | ||
options.callback = lastArg | ||
} | ||
|
||
return options | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'json' | ||
package_json = JSON.parse(File.read('package.json')) | ||
|
||
Pod::Spec.new do |s| | ||
|
||
s.name = package_json["name"] | ||
s.version = package_json["version"] | ||
s.summary = package_json["description"] | ||
s.homepage = package_json["homepage"] | ||
s.license = package_json["license"] | ||
s.author = { package_json["author"] => package_json["author"] } | ||
s.platform = :ios, "7.0" | ||
s.source = { :git => package_json["repository"]["url"].gsub(/(http.*)/).first, :tag => "v#{s.version}" } | ||
s.source_files = 'ios/**/*.{h,m}' | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const assert = require('assert') | ||
const normalizeBindOptions = require('../normalizeBindOptions') | ||
const prettify = obj => JSON.stringify(obj, null, 2) | ||
|
||
describe('normalizeBindOptions', () => { | ||
|
||
it('should support all combinations of arguments for [port], [address], [callback]', () => { | ||
const args = [ | ||
{ name: 'port', value: 1234 }, | ||
{ name: 'address', value: '1.2.3.4' }, | ||
{ name: 'callback', value: () => {} }, | ||
] | ||
|
||
// check every combination of arguments (retaining order) | ||
// use a bit mask to decide whether to keep an argument | ||
for (let i = 0, numCombinations = Math.pow(2, args.length); i < numCombinations; i++) { | ||
const usedArgs = args.filter((arg, bit) => (i + 1) & 1 << bit) | ||
const expected = {} | ||
usedArgs.forEach(arg => expected[arg.name] = arg.value) | ||
const usedArgsValues = usedArgs.map(arg => arg.value) | ||
|
||
const result = normalizeBindOptions(...usedArgsValues) | ||
try { | ||
assert.deepEqual(result, expected) | ||
} catch (err) { | ||
throw new Error(`for args: ${prettify(usedArgsValues)}\nexpected: ${prettify(expected)}\ngot ${prettify(result)}`) | ||
} | ||
} | ||
}) | ||
|
||
it('should support all combinations of arguments for [options], [callback]', () => { | ||
const callback = () => {} | ||
const inOut = [ | ||
[ | ||
[{ port: 123 }, callback], { port: 123, callback } | ||
], | ||
[ | ||
[{ port: 123 }], { port: 123 } | ||
], | ||
[ | ||
[callback], { callback } | ||
], | ||
] | ||
|
||
for (const [args, expected] of inOut) { | ||
let result | ||
try { | ||
result = normalizeBindOptions(...args) | ||
assert.deepEqual(result, expected) | ||
} catch (err) { | ||
throw new Error(`for args: ${prettify(args)}\nexpected: ${prettify(expected)}\ngot ${prettify(result)}`) | ||
} | ||
} | ||
}) | ||
}) |