-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add
OperationalContext
class for keeping track of complex operations
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
const DATA = Symbol('data'), | ||
PARENT = Symbol('parent'); | ||
|
||
/** | ||
* The OperationalContext class | ||
* | ||
* @constructor | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {Alchemy.OperationalContext} parent | ||
*/ | ||
const OperationalContext = Function.inherits('Alchemy.Base', 'Alchemy.OperationalContext', function OperationalContext(parent) { | ||
|
||
// Store the optional parent context | ||
this[PARENT] = parent || null; | ||
|
||
// Create the data object | ||
this[DATA] = parent ? Object.create(parent[DATA]) : {}; | ||
}); | ||
|
||
/** | ||
* The property creator | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
*/ | ||
OperationalContext.setStatic(function setContextProperty(name, getter, setter) { | ||
|
||
let camelized = name.camelize(), | ||
set_method = 'set' + camelized, | ||
get_method = 'get' + camelized; | ||
|
||
if (setter) { | ||
this.setMethod(set_method, function set(value) { | ||
this[DATA][name] = setter.call(this, value); | ||
return this; | ||
}); | ||
} else { | ||
this.setMethod(set_method, function set(value) { | ||
this[DATA][name] = value; | ||
return this; | ||
}); | ||
} | ||
|
||
if (getter) { | ||
this.setMethod(get_method, function get() { | ||
return getter.call(this, this[DATA][name]); | ||
}); | ||
} else { | ||
this.setMethod(get_method, function get() { | ||
return this[DATA][name]; | ||
}); | ||
} | ||
}); | ||
|
||
/** | ||
* Get the parent | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @return {Alchemy.OperationalContext} | ||
*/ | ||
OperationalContext.setMethod(function getParent() { | ||
return this[PARENT]; | ||
}); | ||
|
||
/** | ||
* Set the parent | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {Alchemy.OperationalContext} context | ||
*/ | ||
OperationalContext.setMethod(function setParent(context) { | ||
return this[PARENT] = context; | ||
}); | ||
|
||
/** | ||
* Create a new child instance | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @return {OperationalContext} | ||
*/ | ||
OperationalContext.setMethod(function createChild() { | ||
return new this.constructor(this); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,6 +271,15 @@ const core_classes = load_core.createStage('core_classes', () => { | |
*/ | ||
alchemy.hawkejs.load(resolveCorePath('class', 'schema_client'), CLIENT_HAWKEJS_OPTIONS); | ||
|
||
/** | ||
* Require the operational_context class on the client side too | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
*/ | ||
alchemy.hawkejs.load(resolveCorePath('class', 'operational_context'), CLIENT_HAWKEJS_OPTIONS); | ||
|
||
/** | ||
* Require the setting classes on the client side too | ||
* | ||
|