plusui-native-core 0.1.59 → 0.1.62

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## 🎯 Overview
4
4
 
5
- The **Connection Feature** is PlusUI's absurdly simple system for frontend ↔ backend communication. Both sides use the same two methods: **`emit()`** and **`on()`**.
5
+ The **Connection Feature** is PlusUI's absurdly simple system for frontend ↔ backend communication. Use **`feature.emit()`** and **`feature.on()`** on frontend, mirrored by scoped channels on backend.
6
6
 
7
7
  ## ✨ The 5 Primitives That Cover Everything
8
8
 
@@ -32,13 +32,15 @@ Just `emit()` and `on()` handle all communication patterns:
32
32
  ```typescript
33
33
  import { connect } from 'plusui-native-core/connect';
34
34
 
35
+ const custom = connect.feature('custom');
36
+
35
37
  // Listen for response
36
- connect.on('greetResponse', (data) => {
38
+ custom.on('greetResponse', (data) => {
37
39
  console.log(data.message); // "Hello, World!"
38
40
  });
39
41
 
40
42
  // Send message to backend
41
- connect.emit('greet', { name: 'World' });
43
+ custom.emit('greet', { name: 'World' });
42
44
  ```
43
45
 
44
46
  ### Receive & Respond
@@ -48,23 +50,25 @@ connect.emit('greet', { name: 'World' });
48
50
 
49
51
  plusui::Connect connect;
50
52
 
51
- connect.on("greet", [&connect](const nlohmann::json& payload) {
53
+ auto customFeature = connect.feature("custom");
54
+
55
+ customFeature.on("greet", [&connect](const nlohmann::json& payload) {
52
56
  std::string user = payload.value("name", "World");
53
- connect.emit("greetResponse", {{"message", "Hello, " + user + "!"}});
57
+ connect.emit("custom.greetResponse", {{"message", "Hello, " + user + "!"}});
54
58
  });
55
59
 
56
60
  // Wire backend connect ↔ window bridge once
57
61
  plusui::bindConnect(mainWindow, connect);
58
62
 
59
63
  // Example: backend push to frontend
60
- connect.emit("resize", {{"width", 1280}, {"height", 720}});
64
+ connect.emit("custom.resize", {{"width", 1280}, {"height", 720}});
61
65
  ```
62
66
 
63
67
  ### Listen on Frontend
64
68
 
65
69
  ```typescript
66
70
  // Listen for messages from backend
67
- connect.on('resize', (data) => {
71
+ custom.on('resize', (data) => {
68
72
  console.log(`${data.width}x${data.height}`);
69
73
  updateLayout(data);
70
74
  });
@@ -152,6 +156,12 @@ connect.on("custom.appEvent", [](const nlohmann::json& payload) {
152
156
  });
153
157
  ```
154
158
 
159
+ `plusui connect` scans frontend and backend `.emit()` / `.on()` calls and understands feature aliases, including:
160
+
161
+ - `const custom = createFeatureConnect('custom'); custom.on('event', ...)`
162
+ - `const custom = connect.feature('custom'); custom.emit('event', ...)`
163
+ - `auto custom = connect.feature("custom"); custom.on("event", ...)`
164
+
155
165
  ## 💡 Design Your Own Patterns
156
166
 
157
167
  ### Request/Response Pattern
@@ -106,6 +106,38 @@ public:
106
106
  }
107
107
  };
108
108
 
109
+ // ============================================================
110
+ // Channel — single-name channel object
111
+ //
112
+ // Mirror of the TypeScript createChannel() object:
113
+ // download.on([](const json& p) { ... });
114
+ // download.emit({{"progress", 50}});
115
+ //
116
+ // Obtained via connect.channel("download") or declared in
117
+ // the auto-generated connections.gen.hpp.
118
+ // ============================================================
119
+ class Channel {
120
+ Connect *owner;
121
+ std::string name_;
122
+
123
+ public:
124
+ Channel() : owner(nullptr) {}
125
+ Channel(Connect *parent, std::string channelName)
126
+ : owner(parent), name_(std::move(channelName)) {}
127
+
128
+ // Register a listener — mirrors TypeScript: download.on((d) => { ... })
129
+ void on(EventHandler handler) {
130
+ if (owner) owner->on(name_, std::move(handler));
131
+ }
132
+
133
+ // Send a message — mirrors TypeScript: download.emit({ key: value })
134
+ void emit(const nlohmann::json &payload = nlohmann::json::object()) {
135
+ if (owner) owner->emit(name_, payload);
136
+ }
137
+
138
+ const std::string &name() const { return name_; }
139
+ };
140
+
109
141
  private:
110
142
  std::function<void(const std::string &)> outboundHandler;
111
143
  std::map<std::string, std::vector<EventHandler>> eventHandlers;
@@ -145,6 +177,13 @@ public:
145
177
 
146
178
  Feature feature(const std::string &scope) { return Feature(this, scope); }
147
179
 
180
+ // Create a named channel object — mirrors TypeScript createChannel('name')
181
+ // Returns by value; store as a member or local:
182
+ // auto download = connect.channel("download");
183
+ // download.on([](const json& p) { ... });
184
+ // download.emit({{"progress", 50}});
185
+ Channel channel(const std::string &name) { return Channel(this, name); }
186
+
148
187
  // Request/response helper for call primitive
149
188
  void onCall(const std::string &name, CallHandler handler) {
150
189
  callHandlers[name] = std::move(handler);
@@ -31,7 +31,6 @@
31
31
  #include <plusui/filedrop.hpp>
32
32
  #include <plusui/keyboard.hpp>
33
33
  #include <plusui/menu.hpp>
34
- #include <plusui/native_bindings.hpp>
35
34
  #include <plusui/tray.hpp>
36
35
  #include <plusui/webgpu.hpp>
37
36
  #include <plusui/window.hpp>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plusui-native-core",
3
- "version": "0.1.59",
3
+ "version": "0.1.62",
4
4
  "description": "PlusUI Core framework (frontend + backend implementations)",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,19 +0,0 @@
1
- #pragma once
2
-
3
- #include <string>
4
- #include <vector>
5
-
6
- namespace plusui {
7
-
8
- struct BindingEntry {
9
- const char *source;
10
- const char *feature;
11
- const char *method;
12
- };
13
-
14
- class NativeBindings {
15
- public:
16
- static const std::vector<BindingEntry> &getEntries();
17
- };
18
-
19
- } // namespace plusui