Last active
December 18, 2017 04:22
-
-
Save Inviz/77a0746d05194671b7141dbf34a9ac38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Loosely-formed runtime implementation of following action scheme: | |
// http://www.site.uottawa.ca/~bochmann/ELG7187C/CourseNotes/BehaviorModeling/Petri-nets/Orders%20-%20activity%20diagram.jpg | |
// async properties, which need some kind of outside world interaction to fill up | |
// - order.accepted - decided by admin | |
// - order.invoice - an object that holds details of payment request | |
// - order.payment - details of fulfilled payment | |
// - order.shipment - details of fulfilled shipment | |
// variables that can be mutated freely in runtime | |
// - order.accepted | |
// - order.trusted | |
// In code: In Petri: | |
// - Array/Scope - Subnet | |
// - Object - Tokens | |
// - Key - Place | |
// - Observer - Transition | |
// - Dependency - Ark | |
// The G language deals with asynchronicity of transitions, | |
// propagating changes in steps, unrolling and migrating effects | |
// For each entry in `app.incoming_orders` | |
var IncomingOrder = { | |
// Auto-accept trusted orders | |
'trusted == true': function() { | |
this.set('accepted', true); | |
}, | |
// Request administrator validation | |
'trusted == false': function() { | |
this.set('accepted', this.prompt('Approval')) | |
}, | |
// Close invalid orders | |
'accepted == false': function() { | |
this.set('closed', true); | |
}, | |
// Send invoice if order is valid | |
'accepted == true': function() { | |
this.set('invoice', this.prompt('Invoice')) | |
}, | |
// When invoice is sent, request for payment | |
'invoice': function() { | |
this.set('payment', this.prompt('Payment')); | |
}, | |
// Ship goods right after invoice for trusted orders | |
'invoice && trusted == true && accepted == true': function() { | |
this.set('shipment', this.prompt('Shipment')) | |
}, | |
// Ensure shipment is requested when payment is received | |
'payment': function() { | |
this.set('shipment', this.prompt('Shipment')) | |
}, | |
// Once both shipment and payment is complete, close order | |
'shipment && payment': function() { | |
this.set('closed', true); | |
} | |
} | |
var InvoicePetri = new G.Petri({ | |
Order: { | |
collection: 'orders', | |
attributes: { | |
title: String, | |
description: String, | |
closed: false, | |
trusted: false, | |
accepted: false | |
}, | |
scopes: { | |
incoming: { | |
condition: 'closed == false', | |
network: IncomingOrder | |
}, | |
closed: { | |
condition: 'closed == true && accepted == false' | |
}, | |
fulfilled: { | |
condition: 'closed == true && accepted == true' | |
} | |
} | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment