Skip to content

Commit 4e3f5c1

Browse files
committed
update: ramda -> rambda
1 parent cdf0f46 commit 4e3f5c1

12 files changed

+120
-113
lines changed

packages/core/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @webscopeio/react-firebase-messenger
22

3+
## 0.0.5
4+
5+
### Patch Changes
6+
7+
- Update: replace ramda with rambda (+ts fixes)
8+
39
## 0.0.4
410

511
### Patch Changes
Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import R from 'ramda'
1+
import { compose, map, toPairs, assoc, dissoc, evolve, sortBy, prop, values, reverse, indexBy, keys } from 'rambda'
22

33
import { ChatMessage, ChatUser, CollectionObject, Message, UserChatsEntity } from '../models/database'
44
import { toUnixTimestamp, unixToJSDate } from './time-convertors'
@@ -10,27 +10,28 @@ import { toUnixTimestamp, unixToJSDate } from './time-convertors'
1010
* From `Message`s to `ChatMessage`s.
1111
*/
1212
export const transformMessagesToStoreInDB = (userId: string) =>
13-
R.compose<Message[][], CollectionObject<Message>, CollectionObject<ChatMessage>, Array<[string, ChatMessage]>>(
14-
R.toPairs,
15-
R.map(
16-
// TODO: Get rid of the any
17-
R.compose<any, any, any, any, any>(
18-
R.evolve({
13+
compose<Message[][], CollectionObject<Message>, CollectionObject<ChatMessage>, Array<[string, ChatMessage]>>(
14+
toPairs,
15+
// @ts-ignore evolved type is not correct with map
16+
map(
17+
compose(
18+
// @ts-ignore evolved type is not correct with map
19+
evolve({
1920
createdAt: toUnixTimestamp,
2021
}),
21-
R.assoc('userId', userId),
22-
R.dissoc('_id'),
23-
R.dissoc('user'),
22+
assoc('userId', userId),
23+
dissoc('_id'),
24+
dissoc('user'),
2425
),
2526
),
26-
R.indexBy(R.prop('_id')),
27-
)
27+
indexBy(prop('_id')),
28+
) as (messages: Message[]) => Array<[string, ChatMessage]>
2829

2930
// Create user object in GiftedChat requires shape
3031
const createUserObject = (participants: CollectionObject<ChatUser>) => (messageObject: ChatMessage) => {
3132
const participant = participants[messageObject.userId]
3233

33-
return R.assoc(
34+
return assoc(
3435
'user',
3536
{
3637
_id: messageObject.userId,
@@ -43,58 +44,59 @@ const createUserObject = (participants: CollectionObject<ChatUser>) => (messageO
4344

4445
// handling list of messages which are got from firebase
4546
export const loadMoreMessagesListTransform = (participants: CollectionObject<ChatUser>) =>
46-
R.compose<CollectionObject<ChatMessage>[], ChatMessage[], Message[], Message[]>(
47-
// R.reverse,
48-
R.sortBy(R.prop('createdAt')),
49-
R.map(
50-
R.compose<any, any, any, any>(
51-
R.dissoc('userId'),
52-
R.evolve({
47+
compose<CollectionObject<ChatMessage>[], ChatMessage[], Message[], Message[]>(
48+
// reverse,
49+
sortBy(prop('createdAt')),
50+
map(
51+
compose<any, any, any, any>(
52+
dissoc('userId'),
53+
evolve({
5354
createdAt: unixToJSDate,
5455
}),
5556
createUserObject(participants),
5657
),
5758
),
58-
R.values,
59+
values,
5960
)
6061

6162
// handling one single message which is got from firebase
6263
export const listnerSingleMessageTransform = (
6364
messageSnippetKey: string | null,
6465
participants: CollectionObject<ChatUser>,
6566
) =>
66-
R.compose<
67+
compose<
6768
ChatMessage[],
6869
ChatMessage & { user: Message['user'] },
6970
ChatMessage & Message,
7071
Omit<ChatMessage & Message, 'userId'>,
7172
Message
7273
>(
73-
R.dissoc('userId'),
74-
R.evolve<any>({
74+
dissoc('userId'),
75+
evolve<any>({
7576
createdAt: unixToJSDate,
7677
}),
77-
R.assoc('_id', messageSnippetKey),
78+
// @ts-ignore
79+
assoc('_id', messageSnippetKey),
7880
createUserObject(participants),
79-
)
81+
) as (...messages: ChatMessage[]) => Message
8082

8183
// Transform data into FlatList requires shape
8284
export const toFlatList = (userChats: CollectionObject<Omit<UserChatsEntity, 'chatId'>>) =>
83-
R.compose<
85+
compose<
8486
CollectionObject<Omit<UserChatsEntity, 'chatId'>>[],
8587
any,
8688
Array<UserChatsEntity>,
8789
Array<UserChatsEntity>,
8890
Array<UserChatsEntity>
89-
>(R.reverse, R.sortBy(R.prop('lastMessageCreatedAt')), R.values, (item) => {
90-
const keys = R.keys(item)
91-
keys.forEach(
91+
>(reverse, sortBy(prop('lastMessageCreatedAt')), values, (item) => {
92+
const lKeys = keys(item)
93+
lKeys.forEach(
9294
// @ts-ignore // TODO: fix this however it should not throw error even it does :(
93-
(key) => (item[key] = R.compose(R.assoc('chatId', key))(item[key])),
95+
(key) => (item[key] = compose(assoc('chatId', key))(item[key])),
9496
)
9597

9698
return item
9799
})(userChats)
98100

99101
// eslint-disable-next-line no-underscore-dangle
100-
export const getMessagesIds = R.map<Message, string>((message) => message._id)
102+
export const getMessagesIds = map<Message, string>((message) => message._id)

packages/core/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@webscopeio/react-firebase-messenger",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"main": "./dist/index.js",
55
"module": "./dist/index.mjs",
66
"types": "./dist/index.d.ts",
@@ -30,19 +30,20 @@
3030
"devDependencies": {
3131
"@turbo/gen": "^1.10.12",
3232
"@types/node": "^20.5.2",
33-
"@types/ramda": "^0.29.3",
3433
"@types/react": "^18.2.5",
3534
"@types/react-dom": "^18.2.3",
35+
"dayjs": "^1.11.9",
3636
"eslint-config-custom": "workspace:^",
37+
"rambda": "^8.3.0",
3738
"tsconfig": "workspace:*",
3839
"tsup": "^7.2.0",
3940
"typescript": "^5.2.2"
4041
},
4142
"volta": {
4243
"node": "18.17.1"
4344
},
44-
"dependencies": {
45+
"peerDependencies": {
4546
"dayjs": "^1.11.9",
46-
"ramda": "^0.29.0"
47+
"rambda": "^8.3.0"
4748
}
4849
}

packages/native/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @webscopeio/react-firebase-messenger-native
22

3+
## 0.0.5
4+
5+
### Patch Changes
6+
7+
- Update: replace ramda with rambda (+ts fixes)
8+
- Updated dependencies
9+
- @webscopeio/react-firebase-messenger@0.0.5
10+
311
## 0.0.4
412

513
### Patch Changes

packages/native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@webscopeio/react-firebase-messenger-native",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"main": "./dist/index.js",
55
"module": "./dist/index.mjs",
66
"types": "./dist/index.d.ts",

packages/web/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @webscopeio/react-firebase-messenger-web
22

3+
## 0.0.5
4+
5+
### Patch Changes
6+
7+
- Update: replace ramda with rambda (+ts fixes)
8+
- Updated dependencies
9+
- @webscopeio/react-firebase-messenger@0.0.5
10+
311
## 0.0.4
412

513
### Patch Changes

packages/web/components/ChatListProvider.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import R from 'ramda'
2+
import { compose, keys, evolve, append, assoc, dissoc } from 'rambda'
33
import { onValue, type DatabaseReference, off, orderByChild, query } from 'firebase/database'
44
import { chatMetadataRef, usersRef, userChatsAllRef } from '../helpers/references'
55
import {
@@ -65,22 +65,22 @@ class ChatListProvider extends React.Component<Props, State> {
6565
const chatMetaRef = chatMetadataRef(firebaseDBRef, chatId)
6666
const chatMetaListener = onValue(chatMetaRef, (chatMetaSnapshot) => {
6767
// TODO resolve any
68-
let chatMetas = R.compose<
68+
let chatMetas = compose<
6969
Omit<UserChatsEntity & { users: ChatMetadata['users'] }, 'participants'>[],
7070
UserChatsEntity & { users: ChatMetadata['users'] },
7171
UserChatsEntity & { users: ChatMetadata['users'] }
7272
>(
73-
R.evolve<any>({
74-
users: R.dissoc(uid), // dissoc THE user
73+
evolve<any>({
74+
users: dissoc(uid), // dissoc THE user
7575
}),
76-
R.assoc('participants', []),
76+
assoc('participants', []),
7777
)(chatMetaSnapshot.val())
7878

7979
// TODO how does it have `unreadCount` field
8080
chatMetas.unseenMessages = chatsMetaValues[chatId].unreadCount
8181

8282
Promise.all(
83-
R.keys(chatMetas.users).map(
83+
keys(chatMetas.users).map(
8484
(id) =>
8585
new Promise((resolve) => {
8686
// It is save to cast `id` to string
@@ -93,11 +93,11 @@ class ChatListProvider extends React.Component<Props, State> {
9393
uid: participantId,
9494
}
9595

96-
chatMetas = R.compose(
97-
R.evolve({
98-
participants: R.append(userData),
96+
chatMetas = compose(
97+
evolve({
98+
participants: append(userData),
9999
}),
100-
)(chatMetas)
100+
)(chatMetas) as UserChatsEntity & { users: ChatMetadata['users'] }
101101

102102
allChatsParticipants[participantId] = true
103103
// resolve participantId just to fulfill the promise

packages/web/components/ChatWindowProvider.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import R from 'ramda'
2+
import { append, prepend, last, concat, values, reverse, difference, assoc, keys } from 'rambda'
33
import {
44
type DatabaseReference,
55
limitToLast,
@@ -20,6 +20,7 @@ import {
2020
type ChatUser,
2121
type CollectionObject,
2222
type Message,
23+
ChatMessage,
2324
} from '@webscopeio/react-firebase-messenger'
2425

2526
type Props = {
@@ -82,7 +83,7 @@ const ChatProviderWrapper = (
8283
* from value listener as we will listen only to child_added events after that. In order
8384
* to display lates send message.
8485
*/
85-
const processedMessages: Message[] = []
86+
const processedMessages: Array<Message> = []
8687

8788
messagesSnap.forEach((messageSnippet) => {
8889
const message = listnerSingleMessageTransform(messageSnippet.key, participants)(messageSnippet.val())
@@ -113,8 +114,8 @@ const ChatProviderWrapper = (
113114
}
114115

115116
const updatedMesseges = webMessageTransform
116-
? R.append(message, this.state.messages)
117-
: R.prepend(message, this.state.messages)
117+
? append(message, this.state.messages)
118+
: prepend(message, this.state.messages)
118119

119120
this.setState({
120121
messages: updatedMesseges,
@@ -139,15 +140,15 @@ const ChatProviderWrapper = (
139140
}) =>
140141
(messages: Array<Message>) => {
141142
const newChatMetaUpdate: Omit<ChatMetadata, 'isCustom' | 'shiftId'> = {
142-
lastMessageText: R.last(messages)?.text || '',
143-
lastMessageCreatedAt: R.last(messages)?.createdAt || new Date(),
143+
lastMessageText: last(messages)?.text || '',
144+
lastMessageCreatedAt: last(messages)?.createdAt || new Date(),
144145
lastMessageAuthorId: uid,
145146
users: {},
146147
eventId,
147148
// now all of them are private by default
148149
type: 'private',
149150
}
150-
const participants = R.concat([uid], recipientsIds)
151+
const participants = concat([uid], recipientsIds)
151152

152153
participants.forEach((id) => {
153154
newChatMetaUpdate.users[id] = true
@@ -193,8 +194,8 @@ const ChatProviderWrapper = (
193194
eventId,
194195
recipientsIds,
195196
meta: {
196-
lastMessageText: R.last<Message>(messages)?.text ?? '',
197-
lastMessageCreatedAt: R.last<Message>(messages)?.createdAt || new Date(),
197+
lastMessageText: last(messages)?.text ?? '',
198+
lastMessageCreatedAt: last(messages)?.createdAt || new Date(),
198199
lastMessageAuthorId: uid,
199200
},
200201
})
@@ -234,7 +235,7 @@ const ChatProviderWrapper = (
234235
queryRef,
235236
(chatMsgs) => {
236237
const messagesFromDB = chatMsgs.val() as CollectionObject<any>
237-
if (R.values(messagesFromDB).length > this.state.messages.length) {
238+
if (values(messagesFromDB).length > this.state.messages.length) {
238239
// add to message's id to other message's object
239240
chatMsgs.forEach((item) => {
240241
/* eslint-disable no-underscore-dangle */
@@ -248,7 +249,7 @@ const ChatProviderWrapper = (
248249
{
249250
hasMoreToLoad,
250251
isLoadingEarlier: false,
251-
messages: webMessageTransform ? loadedMessages : R.reverse(loadedMessages),
252+
messages: webMessageTransform ? loadedMessages : reverse(loadedMessages),
252253
messagesCount: updatedMsgsCount,
253254
},
254255
callBack || emptyFunc,
@@ -268,11 +269,11 @@ const ChatProviderWrapper = (
268269
const messagesIds = getMessagesIds(messages)
269270
const prevMessagesIds = getMessagesIds(prevMessages)
270271

271-
const diff = R.difference(messagesIds, prevMessagesIds)
272+
const diff = difference(messagesIds, prevMessagesIds)
272273

273274
if (diff.length) {
274275
const unreadMessagesToDeleteUpdate = diff.reduce((result, messageId) => {
275-
const newResult = R.assoc(`unread-messages/${uid}/${messageId}`, null, result || {})
276+
const newResult = assoc(`unread-messages/${uid}/${messageId}`, null, result || {})
276277
return newResult
277278
}, {})
278279

@@ -286,7 +287,7 @@ const ChatProviderWrapper = (
286287
getChatParticipantsDetails = async (participants: CollectionObject<true>) => {
287288
const allChatsParticipants: CollectionObject<object> = {}
288289
await Promise.all(
289-
R.keys(participants).map(
290+
keys(participants).map(
290291
// participantId is definitely string
291292
(participantId) =>
292293
new Promise((resolve) =>

0 commit comments

Comments
 (0)