Skip to content

Commit

Permalink
Updated Release
Browse files Browse the repository at this point in the history
  • Loading branch information
catpea committed Nov 10, 2024
1 parent f7995ef commit 713fff8
Show file tree
Hide file tree
Showing 20 changed files with 246 additions and 99 deletions.
37 changes: 29 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@
</head>
<script type="module">

globalThis.sweetpea = {
prefix: 'x',
};
// import {BindElement} from './src/plugins/elements/index.js';
Object.defineProperty(globalThis, 'VPL_ELEMENT_PREFIX', {
value: 'x', // Value of the constant
writable: false, // Prevent modification of the constant
enumerable: false, // Make it enumerable (optional, for iteration)
configurable: false // Prevent deletion or reconfiguration of the constant
});



import masticator from 'masticator';
await masticator('css/style.css', 'css/bootstrap.min.css','css/bootstrap-icons.min.css');
Expand All @@ -71,10 +75,10 @@
await SuperElement.load();

// RISC
customElements.define(`${globalThis.sweetpea.prefix}-stage`, StageElement);
customElements.define(`${globalThis.sweetpea.prefix}-valve`, ValveElement);
customElements.define(`${globalThis.sweetpea.prefix}-super`, SuperElement); // load super before cable
customElements.define(`${globalThis.sweetpea.prefix}-cable`, CableElement); // load after super
customElements.define(`${VPL_ELEMENT_PREFIX}-stage`, StageElement);
customElements.define(`${VPL_ELEMENT_PREFIX}-valve`, ValveElement);
customElements.define(`${VPL_ELEMENT_PREFIX}-super`, SuperElement); // load super before cable
customElements.define(`${VPL_ELEMENT_PREFIX}-cable`, CableElement); // load after super

</script>

Expand All @@ -87,8 +91,25 @@


<x-stage controls minimap template="stage" theme="original">



<x-super id="guid-18865fe2-de5f-43f0-abc0-3426e6e3a672" x="427" y="32" supervisor="system/standard" worker="stage/director" data-text="" selected="false"></x-super>
<x-super id="guid-92e560db-8df1-49e9-a33e-dc1e84745721" x="80" y="187" supervisor="system/standard" worker="stage/parameter" data-text="" data-json="{&quot;url&quot;:&quot;example.com&quot;}" selected="false"></x-super>
<x-super id="guid-b1742e3d-bf2b-4dff-9906-3bd2204c4af3" x="790" y="195" supervisor="system/standard" worker="logging-and-monitoring/console" data-text="" data-context="info" selected="false"></x-super>

<x-cable id="guid-938cee5a-4329-4a2c-a5f8-2f787bc90097" from="guid-92e560db-8df1-49e9-a33e-dc1e84745721:output" to="guid-18865fe2-de5f-43f0-abc0-3426e6e3a672:start-message" selected="false"></x-cable>
<x-cable id="guid-b5b52451-178f-4579-b1bd-18bda31a3028" from="guid-18865fe2-de5f-43f0-abc0-3426e6e3a672:start-event" to="guid-b1742e3d-bf2b-4dff-9906-3bd2204c4af3:input" selected="false"></x-cable>

<x-super id="guid-c8b532ee-65ff-43d8-af43-4d2497081566" x="173" y="422" supervisor="system/standard" worker="stage/listener" data-text="" data-event="start" selected="false"></x-super>
<x-super id="guid-deaabf37-4aad-4e85-930f-e89c24b9f280" x="585" y="423" supervisor="system/standard" worker="logging-and-monitoring/console" data-text="" data-context="warn" selected="true"></x-super>
<x-cable id="guid-9b2eeaf4-68de-4c80-ad6f-30bd8ba3ff38" from="guid-c8b532ee-65ff-43d8-af43-4d2497081566:output" to="guid-deaabf37-4aad-4e85-930f-e89c24b9f280:input" selected="false"></x-cable>
</x-stage>





<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-fullscreen modal-dialog-scrollable">

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sweetpea",
"type": "module",
"version": "1.0.4",
"version": "1.1.0",
"description": "Signal and Web Component Enhanced Web Apps",
"main": "index.html",
"scripts": {
Expand Down
7 changes: 4 additions & 3 deletions src/plug-ins/dataset-store/DatasetStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default function main (el){

return new Proxy(dataStore, {
get(dataStore, key) {
if (key === 'destroy') return ()=>dataStore.destroy();
if (key === 'parameters') return dataStore.parameters();
return dataStore.getSignal(key);
},
Expand Down Expand Up @@ -55,11 +56,11 @@ class DataStore {
this.subscriptions.map(s=>s.subscription())
}

set gc(v){ // shorthand for component level garbage collection
this.subscriptions.push( {type:'gc-standard', id:'gc-'+this.subscriptions.length, subscription: ()=>v} );
set gc(subscription){ // shorthand for component level garbage collection
this.subscriptions.push( {type:'gc-standard', id:'gc-'+this.subscriptions.length, subscription} );
}

stop() {
destroy() {
this.#observer.disconnect();
this.collectGarbage();
}
Expand Down
115 changes: 63 additions & 52 deletions src/plug-ins/event-emitter/EventEmitter.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,75 @@
export default class EventEmitter {
constructor() {
this.events = {};
}
constructor() {
this.events = {};
}

// Register an event handler
on(event, listener) {
/////console.log('Subscriber', event);
if (!this.events[event]) {
this.events[event] = [];
}
this.events[event].push(listener);
return ()=>this.removeListener(event, listener);
}
stats() {
return Object.fromEntries(Object.entries(this.events).map(([name, listeners])=>[name,listeners.length]))
}

// Register a one-time event handler
once(event, listener) {
const onceWrapper = (...args) => {
listener(...args);
this.removeListener(event, onceWrapper);
};
this.on(event, onceWrapper);
// Register an event handler
on(event, listener) {
if (!this.events[event]) {
this.events[event] = [];
}
this.events[event].push(listener);
return () => this.removeListener(event, listener);
}

// Trigger an event
emit(event, ...args) {
//console.log('Emitting...', event, ...args);
if (this.events[event]) {
this.events[event].forEach(listener => {
listener(...args);
});
}
}
// Register a one-time event handler
once(event, listener) {
const onceWrapper = (...args) => {
listener(...args);
this.removeListener(event, onceWrapper);
};
this.on(event, onceWrapper);
}

// Remove a specific listener
removeListener(event, handlerToRemove) {
if (this.events[event]) {
this.events[event] = this.events[event].filter(handler => handler !== handlerToRemove);
}
// Trigger an event
emit(event, ...args) {
if (this.events[event]) {
this.events[event].forEach((listener) => {
listener(...args);
});
}


// Remove all listeners for a specific event
removeAllListeners(event = null) {
if (event) {
if (this.events[event]) {
delete this.events[event];
}
} else {
// Remove all listeners for all events
this.events = {};
}
if (this.events["*"]) {
this.events["*"].forEach((listener) => {
listener(event, ...args);
});
}
}

send(...a){
this.emit(...a)
}
off(...a){
this.removeListener(...a)
// Remove a specific listener
removeListener(event, handlerToRemove) {
console.log(`removeListener`, event)
if (this.events[event]) {
this.events[event] = this.events[event].filter(
(handler) => handler !== handlerToRemove,
);
}
destroy(){
this.removeAllListeners();
}

// Remove all listeners for a specific event
removeAllListeners(event = null) {
if (event) {
if (this.events[event]) {
console.log(`removeAllListener`, event)
delete this.events[event];
}
} else {
// Remove all listeners for all events
Object.keys(this.events).map(o=>console.log(`removeAllListener`, o))
this.events = {};
}
}

send(...a) {
this.emit(...a);
}
off(...a) {
this.removeListener(...a);
}
destroy() {
this.removeAllListeners();
}
}
22 changes: 17 additions & 5 deletions src/plug-ins/system-integration/SystemIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ export class SystemWorker extends EventEmittter {
this.data = data;
}

subscriptions = []; // {type:'list/item/value', id:'', run}
collectGarbage(){
this.subscriptions.forEach(s=>s.subscription())
}

set gc(subscription){ // shorthand for component level garbage collection
this.subscriptions.push( {type:'gc-standard', id:'gc-'+this.subscriptions.length, subscription} );
}

async connect(){

Expand All @@ -31,14 +38,14 @@ export class SystemWorker extends EventEmittter {
const buffer = this.buffer;

// When message is sent to this actor
actor.on('input', input => {
this.gc = actor.on('input', input => {
// console.log(`${this.constructor.name} got input packet!`, input);

queue.enqueue( input );
});

// When a new order is added to the queue
queue.on('enqueue', async order => {
this.gc = queue.on('enqueue', async order => {

// console.log(`${this.constructor.name} queue order!`, order);

Expand Down Expand Up @@ -66,7 +73,7 @@ export class SystemWorker extends EventEmittter {
});

// When a product is added to the buffer
buffer.on('enbuffer', product => {
this.gc = buffer.on('enbuffer', product => {
// Send the product out to another part of the system
actor.send('output', product );

Expand All @@ -75,7 +82,7 @@ export class SystemWorker extends EventEmittter {
});

// Control protocol aka DATA PULL
actor.on('control', async control=>{
this.gc = actor.on('control', async control=>{
// console.log(`${this.constructor.name} got control packet!`, control);
switch(control.event) {
case 'request':
Expand Down Expand Up @@ -122,7 +129,12 @@ export class SystemWorker extends EventEmittter {
async disconnected(){ // disconnect from stage
// unsubscribe
}

async destroy(){ // disconnect from stage
console.log('Destroy!', this.stage.stats());
this.removeAllListeners();
this.collectGarbage()
console.log('Destroyed!', this.stage.stats());
}

async diagnostic(){
}
Expand Down
2 changes: 1 addition & 1 deletion src/plug-ins/theoretical/Stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default class Stage extends Theoretical {
if(!actorIsSelected) continue;

if(actor.tagName == 'SUPER'){ // Before removing a SUPPERVISOR element remove the cables!
for (const cable of this.core.host.querySelectorAll(`${globalThis.sweetpea.prefix}-cable`)) {
for (const cable of this.core.host.querySelectorAll(`${VPL_ELEMENT_PREFIX}-cable`)) {
if(cable.getAttribute('from').split(':')[0] === actor.getAttribute('id')) cable.remove();
if(cable.getAttribute('to').split(':')[0] === actor.getAttribute('id')) cable.remove();
}
Expand Down
1 change: 0 additions & 1 deletion src/plug-ins/theoretical/SuperElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default class SuperElement extends HTMLElement {
'worker': () => {
if (!newValue) return;
const [category, type] = newValue.split('/');
console.log({category, type})
this.instance.workerCategory.set(category);
this.instance.workerType.set(type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/plug-ins/water-closet/core/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default Inheritance => class Core extends Inheritance {
}

getAllActorsOnStage(){
return this.getStage().querySelectorAll(`${globalThis.sweetpea.prefix}-super, ${globalThis.sweetpea.prefix}-cable`);
return this.getStage().querySelectorAll(`${VPL_ELEMENT_PREFIX}-super, ${VPL_ELEMENT_PREFIX}-cable`);
}


Expand Down
2 changes: 1 addition & 1 deletion src/plug-ins/water-closet/data/Data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default Inheritance => class Data extends Inheritance {
super(...a);

this.data = datasetStore(this.host);
this.gc =()=> this.data.disconnect();
this.gc =()=> this.data.destroy();

// console.log('data initialized');
}
Expand Down
6 changes: 3 additions & 3 deletions src/plug-ins/water-closet/element-search/ElementSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export default Inheritance => class ElementSearch extends Inheritance {
//console.log('VVV', this);
//console.log('VVV', this.host.tagName.toLowerCase());

if(this.host.tagName.toLowerCase() == `${globalThis.sweetpea.prefix}-stage`){
if(this.host.tagName.toLowerCase() == `${VPL_ELEMENT_PREFIX}-stage`){
response = this.host;
}else{
response = this.findOut(this.host, `${globalThis.sweetpea.prefix}-stage`);
response = this.findOut(this.host, `${VPL_ELEMENT_PREFIX}-stage`);
}

return response;
Expand Down Expand Up @@ -97,7 +97,7 @@ export default Inheritance => class ElementSearch extends Inheritance {

isOutermostElement(parents) {

const hasInnerDataTag = !!parents.map(p => p.tagName).find(tag => tag.startsWith(globalThis.sweetpea.prefix + '-'));
const hasInnerDataTag = !!parents.map(p => p.tagName).find(tag => tag.startsWith(VPL_ELEMENT_PREFIX + '-'));
return !hasInnerDataTag;
}

Expand Down
4 changes: 2 additions & 2 deletions src/plug-ins/water-closet/garbage/Garbage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default Inheritance => class Garbage extends Inheritance {
this.subscriptions.map(s=>s.subscription())
}

set gc(v){ // shorthand for component level garbage collection
this.subscriptions.push( {type:'gc-standard', id:'gc-'+this.subscriptions.length, subscription: ()=>v} );
set gc(subscription){ // shorthand for component level garbage collection
this.subscriptions.push( {type:'gc-standard', id:'gc-'+this.subscriptions.length, subscription} );
}
}
2 changes: 1 addition & 1 deletion src/plug-ins/water-closet/project/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default Inheritance => class Project extends Inheritance {
this.getStage().replaceChildren(); // Clear Stage

for (const actorObject of data) {
const actorElement = document.createElement(`${globalThis.sweetpea.prefix}-${actorObject.type}`);
const actorElement = document.createElement(`${VPL_ELEMENT_PREFIX}-${actorObject.type}`);
delete actorObject.type;
for (const [attributeName, attributeValue] of Object.entries(actorObject)) {
actorElement.setAttribute(attributeName, attributeValue);
Expand Down
Loading

0 comments on commit 713fff8

Please sign in to comment.