wappler-pubsub 1.0.0
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/LICENSE.md +22 -0
- package/README.md +40 -0
- package/app_connect/components.hjson +122 -0
- package/includes/dmx-publisher.js +32 -0
- package/includes/dmx-subscriber.js +47 -0
- package/package.json +15 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2025 Amit Chandi
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# wappler_ac_pubsub
|
|
2
|
+
These components provide a simple pub/sub mechanism that allows a partial view to communicate back to its parent page. Instead of tightly coupling partials to the parent’s logic, a partial can publish events, and the parent can subscribe to them and react. This makes partials more modular, reusable, and easier to maintain.
|
|
3
|
+
|
|
4
|
+
## Components
|
|
5
|
+
- **Publisher**: Publish events to notify subscribers about changes.
|
|
6
|
+
- **Subscriber**: Subscribe to events published by publishers and perform actions based on the received events.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
### Publisher
|
|
11
|
+
|
|
12
|
+
#### Properties
|
|
13
|
+
- **ID**: ID of the Publisher
|
|
14
|
+
|
|
15
|
+
#### Actions
|
|
16
|
+
- **Trigger**: Trigger an event with the given Event Name.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
### Subscriber
|
|
21
|
+
|
|
22
|
+
#### Properties
|
|
23
|
+
- **ID**: ID of the Subscriber
|
|
24
|
+
- **Event Name**: The name of the event the component is subscribed to.
|
|
25
|
+
|
|
26
|
+
#### Events
|
|
27
|
+
- **Event Triggered**: Fired when the event set in Event Name is triggered.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Instructions for Intended Use Case
|
|
32
|
+
You are meant to have 1 Publisher and 1 or more Subscribers. Place the Publisher in your layout so all pages under the layout have visibility of the Publisher.
|
|
33
|
+
1. Place a Publisher component in your layout.
|
|
34
|
+
2. Place a Subscriber component in your content page and set the Event Name the subscriber is listening to.
|
|
35
|
+
3. Under the Subscriber's Dynamic Events, setup the action(s) you would like to perform when the event is triggered.
|
|
36
|
+
4. Setup a trigger for your event from a partial using the Trigger Action of your Publisher component.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
The Publisher and Subscriber components are licensed under the MIT License. Please refer to the license file for more details.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{
|
|
2
|
+
components: [
|
|
3
|
+
{
|
|
4
|
+
type: 'dmx-publisher',
|
|
5
|
+
selector : 'dmx-publisher, [is=dmx-publisher]',
|
|
6
|
+
groupTitle : 'Chandiman',
|
|
7
|
+
groupIcon : 'fas fa-archive',
|
|
8
|
+
title : 'Publisher: @@id@@',
|
|
9
|
+
icon : 'fa fa-lg fa-upload',
|
|
10
|
+
state : 'opened',
|
|
11
|
+
anyParent: true,
|
|
12
|
+
template: '<dmx-publisher id="@@id@@"></dmx-publisher>',
|
|
13
|
+
baseName: 'publisher',
|
|
14
|
+
help: 'Publisher',
|
|
15
|
+
dataScheme: [
|
|
16
|
+
|
|
17
|
+
],
|
|
18
|
+
outputType: 'object',
|
|
19
|
+
dataPick: true,
|
|
20
|
+
dataPickObject: true,
|
|
21
|
+
properties : [
|
|
22
|
+
{
|
|
23
|
+
group: 'Publisher Properties',
|
|
24
|
+
variables: [
|
|
25
|
+
{ name: 'publisherId', attribute: 'id', title: 'ID', type: 'text', defaultValue: '', required: true },
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
actionsScheme: [
|
|
30
|
+
{
|
|
31
|
+
addTitle: 'Trigger',
|
|
32
|
+
title : 'Trigger',
|
|
33
|
+
name : 'trigger',
|
|
34
|
+
icon : 'fas fa-lg fa-exchange',
|
|
35
|
+
state : 'opened',
|
|
36
|
+
help: 'Trigger',
|
|
37
|
+
properties : [
|
|
38
|
+
{
|
|
39
|
+
group: 'Trigger Properties',
|
|
40
|
+
optionsInObject: true,
|
|
41
|
+
variables: [
|
|
42
|
+
{
|
|
43
|
+
name: 'name', optionName: 'name', title: 'Event Name', type: 'text',
|
|
44
|
+
dataBindings: true, defaultValue: '',
|
|
45
|
+
help: 'Enter the event name to trigger'
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
children: [],
|
|
53
|
+
allowed_children: {},
|
|
54
|
+
copyFiles: [
|
|
55
|
+
{src: 'includes/dmx-publisher.js', dst: 'js/dmx-publisher.js'},
|
|
56
|
+
],
|
|
57
|
+
linkFiles: [
|
|
58
|
+
{src: 'js/dmx-publisher.js', type: 'js', defer: true},
|
|
59
|
+
],
|
|
60
|
+
cssOrder: [],
|
|
61
|
+
jsOrder: []
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: 'dmx-subscriber',
|
|
65
|
+
selector : 'dmx-subscriber, [is=dmx-subscriber]',
|
|
66
|
+
groupTitle : 'Chandiman',
|
|
67
|
+
groupIcon : 'fas fa-archive',
|
|
68
|
+
title : 'subscriber: @@id@@',
|
|
69
|
+
icon : 'fa fa-lg fa-download',
|
|
70
|
+
state : 'opened',
|
|
71
|
+
anyParent: true,
|
|
72
|
+
template: '<dmx-subscriber id="@@id@@"></dmx-subscriber>',
|
|
73
|
+
baseName: 'subscriber',
|
|
74
|
+
help: 'Subscriber',
|
|
75
|
+
dataScheme: [],
|
|
76
|
+
outputType: 'object',
|
|
77
|
+
dataPick: true,
|
|
78
|
+
dataPickObject: true,
|
|
79
|
+
properties : [
|
|
80
|
+
{
|
|
81
|
+
group: 'Subscriber Properties',
|
|
82
|
+
variables: [
|
|
83
|
+
{ name: 'subscriberId', attribute: 'id', title: 'ID', type: 'text', defaultValue: '', required: true },
|
|
84
|
+
{ name: 'subscriberEventName', attribute: 'eventname', title: 'Event Name', type: 'text', defaultValue: 'event', required: true },
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
actionsScheme: [],
|
|
89
|
+
children: [],
|
|
90
|
+
allowed_children: {},
|
|
91
|
+
copyFiles: [
|
|
92
|
+
{src: 'includes/dmx-subscriber.js', dst: 'js/dmx-subscriber.js'},
|
|
93
|
+
],
|
|
94
|
+
linkFiles: [
|
|
95
|
+
{src: 'js/dmx-subscriber.js', type: 'js', defer: true},
|
|
96
|
+
],
|
|
97
|
+
cssOrder: [],
|
|
98
|
+
jsOrder: []
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
attributes: [],
|
|
102
|
+
events: [
|
|
103
|
+
{
|
|
104
|
+
name: 'dmx-subscriber-event_triggered', attributeStartsWith: 'dmx-on', attribute: 'eventtriggered', title: 'Event Triggered', type: 'boolean',
|
|
105
|
+
display: 'fieldset', icon: 'fa fa-lg fa-chevron-right',
|
|
106
|
+
groupTitle: 'Publisher', groupIcon: 'fa fa-lg fa-archive comp-general',
|
|
107
|
+
defaultValue: true, show: ['event_triggered_action'], noChangeOnHide: true, groupEnabler: true,
|
|
108
|
+
children: [
|
|
109
|
+
{
|
|
110
|
+
name: 'event_triggered_action', attributeStartsWith: 'dmx-on', attribute: 'eventtriggered', isValue: true, actionsPicker: true,
|
|
111
|
+
title: 'Action:', type: 'text', help: 'Choose the action to execute.', defaultValue: '', initDisplay: 'none', required: true
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
allowedOn: {
|
|
115
|
+
'dmx-subscriber' : true
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
static_events: [
|
|
120
|
+
|
|
121
|
+
]
|
|
122
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// JavaScript Document
|
|
2
|
+
|
|
3
|
+
dmx.Component('publisher', {
|
|
4
|
+
initialData: {},
|
|
5
|
+
|
|
6
|
+
attributes: {},
|
|
7
|
+
|
|
8
|
+
render: false,
|
|
9
|
+
|
|
10
|
+
methods: {
|
|
11
|
+
trigger: function (name) {
|
|
12
|
+
this._trigger(name);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
events: {
|
|
17
|
+
updated: Event,
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
init: function () {
|
|
21
|
+
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
preformUpdate: function (updatedProps) {
|
|
25
|
+
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
_trigger: function (props) {
|
|
29
|
+
let customEvent = new CustomEvent(props.name);
|
|
30
|
+
document.dispatchEvent(customEvent);
|
|
31
|
+
},
|
|
32
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// JavaScript Document
|
|
2
|
+
|
|
3
|
+
dmx.Component('subscriber', {
|
|
4
|
+
initialData: {
|
|
5
|
+
eventname: ''
|
|
6
|
+
},
|
|
7
|
+
|
|
8
|
+
attributes: {
|
|
9
|
+
eventname: {
|
|
10
|
+
type: String,
|
|
11
|
+
default: 'event'
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
render: false,
|
|
16
|
+
methods: {},
|
|
17
|
+
|
|
18
|
+
events: {
|
|
19
|
+
updated: Event,
|
|
20
|
+
eventtriggered: Event,
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
init: function () {
|
|
24
|
+
this.set('eventname', this.props.eventname);
|
|
25
|
+
this.handler = () => this._eventtriggered();
|
|
26
|
+
document.addEventListener(this.props.eventname, this.handler);
|
|
27
|
+
this.dispatchEvent("eventtriggered");
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
destroy: function () {
|
|
31
|
+
document.removeEventListener(this.get('eventname'), this.handler);
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
preformUpdate: function (updatedProps) {
|
|
35
|
+
if (updatedProps.has('eventname')) {
|
|
36
|
+
this.set('eventname', this.props.eventname);
|
|
37
|
+
|
|
38
|
+
dmx.nextTick(function () {
|
|
39
|
+
this.dispatchEvent('updated');
|
|
40
|
+
}, this);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
_eventtriggered: function () {
|
|
45
|
+
this.dispatchEvent("eventtriggered");
|
|
46
|
+
},
|
|
47
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wappler-pubsub",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A set of publisher/subscriber App Connect components for Wappler",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"wappler-extension",
|
|
7
|
+
"app-connect",
|
|
8
|
+
"pub/sub"
|
|
9
|
+
],
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Amit Chandi",
|
|
12
|
+
"url": "https://github.com/amitchandi"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT"
|
|
15
|
+
}
|