@ray-js/t-agent 0.2.7-beta.3 → 0.2.7-beta.4

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.
@@ -1,6 +1,4 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import "core-js/modules/esnext.iterator.constructor.js";
3
- import "core-js/modules/esnext.iterator.for-each.js";
4
2
  import "core-js/modules/web.dom-collections.iterator.js";
5
3
  import { ChatMessageStatus } from './types';
6
4
  import { createHooks } from 'hookable';
@@ -36,41 +34,59 @@ export default class ChatSession {
36
34
  return ret;
37
35
  });
38
36
  _defineProperty(this, "initMessages", messages => {
39
- for (const message of messages) {
37
+ for (let i = 0; i < messages.length; i++) {
38
+ const message = messages[i];
40
39
  this.bindMessage(message);
41
- message.set({
42
- status: ChatMessageStatus.FINISH
43
- })._setIsShow();
40
+ // Optimization: Direct assignment to avoid object allocation and excess function calls
41
+ message.status = ChatMessageStatus.FINISH;
42
+ message._setIsShow();
44
43
  }
45
44
  });
46
45
  _defineProperty(this, "getTileById", id => {
47
46
  return this.tileIdIndex.get(id);
48
47
  });
49
48
  _defineProperty(this, "bindTile", tile => {
50
- this.tileIdIndex.set(tile.id, tile);
51
- for (const child of tile.children) {
52
- this.bindTile(child);
49
+ // Iterative approach to avoid recursion overhead
50
+ const stack = [tile];
51
+ while (stack.length > 0) {
52
+ const current = stack.pop();
53
+ this.tileIdIndex.set(current.id, current);
54
+
55
+ // Push children to stack
56
+ if (current.children && current.children.length > 0) {
57
+ for (let i = current.children.length - 1; i >= 0; i--) {
58
+ stack.push(current.children[i]);
59
+ }
60
+ }
53
61
  }
54
62
  });
55
63
  _defineProperty(this, "unbindTile", tile => {
56
- this.tileIdIndex.delete(tile.id);
57
- for (const child of tile.children) {
58
- this.unbindTile(child);
64
+ // Iterative approach
65
+ const stack = [tile];
66
+ while (stack.length > 0) {
67
+ const current = stack.pop();
68
+ this.tileIdIndex.delete(current.id);
69
+ if (current.children && current.children.length > 0) {
70
+ for (let i = current.children.length - 1; i >= 0; i--) {
71
+ stack.push(current.children[i]);
72
+ }
73
+ }
59
74
  }
60
75
  });
61
76
  _defineProperty(this, "bindMessage", message => {
62
77
  this.messages.set(message.id, message);
63
- for (const tile of message.tiles) {
78
+ for (let i = 0; i < message.tiles.length; i++) {
79
+ const tile = message.tiles[i];
64
80
  this.bindTile(tile);
65
81
  }
66
82
  });
67
83
  _defineProperty(this, "unbindMessage", message => {
68
84
  this.messages.delete(message.id);
69
- this.tileIdIndex.forEach(tile => {
70
- if (tile.message.id === message.id) {
71
- this.tileIdIndex.delete(tile.id);
72
- }
73
- });
85
+ // Optimization: Instead of full scan, just unbind tiles known to be in the message
86
+ for (let i = 0; i < message.tiles.length; i++) {
87
+ const tile = message.tiles[i];
88
+ this.unbindTile(tile);
89
+ }
74
90
  });
75
91
  _defineProperty(this, "onChange", fn => this.hooks.hook('onChange', fn));
76
92
  _defineProperty(this, "getLatestMessage", () => {
@@ -85,7 +101,8 @@ export default class ChatSession {
85
101
  this.agent = agent;
86
102
  this.hooks = createHooks();
87
103
  const hooks = ['onChange'];
88
- for (const hook of hooks) {
104
+ for (let i = 0; i < hooks.length; i++) {
105
+ const hook = hooks[i];
89
106
  this[hook] = fn => this.hooks.hook(hook, fn);
90
107
  }
91
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent",
3
- "version": "0.2.7-beta.3",
3
+ "version": "0.2.7-beta.4",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -26,5 +26,5 @@
26
26
  "build": "ray build --type=component --output dist",
27
27
  "clean": "rimraf ./dist"
28
28
  },
29
- "gitHead": "44d1d2ecb71857a1337c20137fe39d25384fdcdb"
29
+ "gitHead": "b10810d37f15c3209ced9fddbfbb94936ad86328"
30
30
  }