Skip to content

Commit f9adfe9

Browse files
committed
Naming changes, Function is now Rpc
1 parent c4a4b52 commit f9adfe9

File tree

5 files changed

+23
-29
lines changed

5 files changed

+23
-29
lines changed

src/api/createNodeFactory.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isFunction, isInteger, isArray } from '../util/is'
22
import createRequest from '../util/createRequest'
33
import localProcedureCall from '../util/localProcedureCall'
4-
import { FUNCTION_CREATOR } from '../const'
4+
import { RPC_CREATOR } from '../const'
55

66
export default function createNodeFactory({ encode, decode }) {
77
return function createNode({
@@ -89,7 +89,7 @@ export default function createNodeFactory({ encode, decode }) {
8989
node.send = (msg) => send(serialize(msg))
9090
return createRemoteFunction({
9191
function_id,
92-
function_creator: FUNCTION_CREATOR.ENTRY,
92+
function_creator: RPC_CREATOR.ENTRY,
9393
})
9494
}
9595

@@ -107,8 +107,8 @@ export default function createNodeFactory({ encode, decode }) {
107107
createRemoteFunction,
108108
caller: fn,
109109
function_creator: is_request
110-
? FUNCTION_CREATOR.REQUEST
111-
: FUNCTION_CREATOR.RESPONSE,
110+
? RPC_CREATOR.REQUEST
111+
: RPC_CREATOR.RESPONSE,
112112
})
113113

114114
let args = msg[2]

src/const.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export const ESCAPE_KEY = '$escape'
2-
export const FUNCTION_KEY = '$f'
2+
export const RPC_KEY = '$f'
33
export const DELETE_KEY = '$d'
44
export const REPLACE_KEY = '$r'
55
export const SPLICE_KEY = '$s'
66
export const SWAP_KEY = '$w'
77
export const MULTI_KEY = '$m'
88

9-
export const FUNCTION_CREATOR = {
9+
export const RPC_CREATOR = {
1010
ENTRY: 'ENTRY',
1111
REQUEST: 'REQUEST',
1212
RESPONSE: 'RESPONSE',

src/types/Function.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ESCAPE_KEY, FUNCTION_KEY } from '../const'
1+
import { ESCAPE_KEY, RPC_KEY } from '../const'
22
import { isValidToEscape, isValidToDecode } from '../util/isValid'
33
import { getUniqueKey } from '../util/get'
44
import { isInteger, isFunction } from '../util/is'
@@ -10,8 +10,8 @@ Rpc.encode = function ({ value, local_rpcs, registerLocalRpcFromEncode }) {
1010
const function_id = local_rpcs.has(value)
1111
? local_rpcs.get(value)
1212
: registerLocalRpcFromEncode(value)
13-
return { [FUNCTION_KEY]: function_id }
14-
} else if (isValidToDecode({ value, key: FUNCTION_KEY })) {
13+
return { [RPC_KEY]: function_id }
14+
} else if (isValidToDecode({ value, key: RPC_KEY })) {
1515
return { [ESCAPE_KEY]: value }
1616
}
1717
return value
@@ -24,19 +24,16 @@ Rpc.decode = function ({
2424
caller,
2525
function_creator,
2626
}) {
27-
if (
28-
getUniqueKey(value) === FUNCTION_KEY &&
29-
isInteger(value[FUNCTION_KEY])
30-
) {
27+
if (getUniqueKey(value) === RPC_KEY && isInteger(value[RPC_KEY])) {
3128
return createRemoteFunction({
32-
function_id: value[FUNCTION_KEY],
29+
function_id: value[RPC_KEY],
3330
function_creator,
3431
caller,
3532
path: path.slice(2),
3633
})
3734
} else if (
3835
isValidToEscape({ value }) &&
39-
isValidToDecode({ value: value[ESCAPE_KEY], key: FUNCTION_KEY })
36+
isValidToDecode({ value: value[ESCAPE_KEY], key: RPC_KEY })
4037
) {
4138
return value[ESCAPE_KEY]
4239
}

src/types/Rpc.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ESCAPE_KEY, FUNCTION_KEY } from '../const'
1+
import { ESCAPE_KEY, RPC_KEY } from '../const'
22
import { isValidToEscape, isValidToDecode } from '../util/isValid'
33
import { getUniqueKey } from '../util/get'
44
import { isInteger, isFunction } from '../util/is'
@@ -10,8 +10,8 @@ Rpc.encode = function ({ value, local_rpcs, registerLocalRpcFromEncode }) {
1010
const function_id = local_rpcs.has(value)
1111
? local_rpcs.get(value)
1212
: registerLocalRpcFromEncode(value)
13-
return { [FUNCTION_KEY]: function_id }
14-
} else if (isValidToDecode({ value, key: FUNCTION_KEY })) {
13+
return { [RPC_KEY]: function_id }
14+
} else if (isValidToDecode({ value, key: RPC_KEY })) {
1515
return { [ESCAPE_KEY]: value }
1616
}
1717
return value
@@ -24,19 +24,16 @@ Rpc.decode = function ({
2424
caller,
2525
function_creator,
2626
}) {
27-
if (
28-
getUniqueKey(value) === FUNCTION_KEY &&
29-
isInteger(value[FUNCTION_KEY])
30-
) {
27+
if (getUniqueKey(value) === RPC_KEY && isInteger(value[RPC_KEY])) {
3128
return createRemoteFunction({
32-
function_id: value[FUNCTION_KEY],
29+
function_id: value[RPC_KEY],
3330
function_creator,
3431
caller,
3532
path: path.slice(2),
3633
})
3734
} else if (
3835
isValidToEscape({ value }) &&
39-
isValidToDecode({ value: value[ESCAPE_KEY], key: FUNCTION_KEY })
36+
isValidToDecode({ value: value[ESCAPE_KEY], key: RPC_KEY })
4037
) {
4138
return value[ESCAPE_KEY]
4239
}

test/createNode.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava'
22
import { createNode } from '../'
3-
import { FUNCTION_CREATOR } from '../src/const'
3+
import { RPC_CREATOR } from '../src/const'
44

55
test('Api', async (t) => {
66
const server = createNode()
@@ -276,22 +276,22 @@ test('rpcFilter API', async (t) => {
276276
// console.log({ function_id, function_creator, caller, path })
277277
t.is(node, server)
278278
if (function_id === 0) {
279-
t.is(function_creator, FUNCTION_CREATOR.ENTRY)
279+
t.is(function_creator, RPC_CREATOR.ENTRY)
280280
t.is(caller, undefined)
281281
t.is(path, undefined)
282282
}
283283
if (function_id === 1) {
284-
t.is(function_creator, FUNCTION_CREATOR.REQUEST)
284+
t.is(function_creator, RPC_CREATOR.REQUEST)
285285
t.is(caller, entryFunction)
286286
t.deepEqual(path, [0])
287287
}
288288
if (function_id === 2) {
289-
t.is(function_creator, FUNCTION_CREATOR.RESPONSE)
289+
t.is(function_creator, RPC_CREATOR.RESPONSE)
290290
t.is(caller, undefined)
291291
t.deepEqual(path, [])
292292
}
293293
if (function_id === 3) {
294-
t.is(function_creator, FUNCTION_CREATOR.REQUEST)
294+
t.is(function_creator, RPC_CREATOR.REQUEST)
295295
t.is(caller, login)
296296
t.deepEqual(path, [0, 'fn'])
297297
}

0 commit comments

Comments
 (0)