@jetthai/cuora 1.0.47 → 1.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.48](https://github.com/jetthai/cuora-module/compare/v1.0.47...v1.0.48) (2021-12-01)
6
+
5
7
  ### [1.0.47](https://github.com/jetthai/cuora-module/compare/v1.0.46...v1.0.47) (2021-11-24)
6
8
 
7
9
  ### [1.0.46](https://github.com/jetthai/cuora-module/compare/v1.0.45...v1.0.46) (2021-11-23)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.47",
3
+ "version": "1.0.48",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,83 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import api from '../api/game'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'game_hot_new',
8
+ initial: 'preparing',
9
+ context: {
10
+ hot: {
11
+ id: null,
12
+ name: 'SYSTEM_TOP_GAME',
13
+ list: [],
14
+ games: [],
15
+ length: 10,
16
+ },
17
+ new: {
18
+ id: null,
19
+ name: 'SYSTEM_NEW_GAME',
20
+ list: [],
21
+ games: [],
22
+ length: 10,
23
+ },
24
+ },
25
+ states: {
26
+ preparing: {
27
+ invoke: {
28
+ src: 'getRoomItems',
29
+ onDone: {
30
+ target: 'fetchingGames',
31
+ actions: 'setId',
32
+ },
33
+ onError: {
34
+ target: 'fetchingGames',
35
+ },
36
+ },
37
+ },
38
+ fetchingGames: {
39
+ invoke: {
40
+ src: 'getGames',
41
+ onDone: {
42
+ actions: 'setGames',
43
+ },
44
+ },
45
+ },
46
+ },
47
+ },
48
+ {
49
+ actions: {
50
+ setId: assign((context, event) => {
51
+ const { list = [] } = event.data
52
+ const hotId = list.find((item) => item.category === context.hot.name)?.id
53
+ const newId = list.find((item) => item.category === context.new.name)?.id
54
+ return {
55
+ hot: { ...context.hot, id: hotId },
56
+ new: { ...context.new, id: newId },
57
+ }
58
+ }),
59
+ setGames: assign((context, event) => {
60
+ const { games } = event.data
61
+ return {
62
+ hot: { ...context.hot, list: games.hot, games: games.hot.slice(0, context.hot.length) },
63
+ new: { ...context.new, list: games.new, games: games.new.slice(0, context.new.length) },
64
+ }
65
+ }),
66
+ },
67
+ services: {
68
+ getRoomItems: async (context, event) => {
69
+ return await request.send(api.getGameCategory({ id: context.roomId }))
70
+ },
71
+ getGames: async (context, event) => {
72
+ const [resHot, resNew] = await Promise.all([
73
+ request.send(api.getGameCategory({ id: context.hot.id })),
74
+ request.send(api.getGameCategory({ id: context.new.id })),
75
+ ])
76
+ const hotGames = resHot?.list?.map?.((item) => item.g)
77
+ const newGames = resNew?.list?.map?.((item) => item.g)
78
+ return { games: { hot: hotGames, new: newGames } }
79
+ },
80
+ },
81
+ }
82
+ )
83
+ }
@@ -8,6 +8,7 @@ import error from './error'
8
8
  import game from './game'
9
9
  import game_favorite from './game_favorite'
10
10
  import game_search from './game_search'
11
+ import game_hot_new from './game_hot_new'
11
12
  import inbox from './inbox'
12
13
  import merge from './merge'
13
14
  import payment_data from './payment_data'
@@ -30,6 +31,7 @@ export default {
30
31
  game,
31
32
  game_favorite,
32
33
  game_search,
34
+ game_hot_new,
33
35
  inbox,
34
36
  merge,
35
37
  payment_data,