/**
* ### Actions functions
*
* Common functions that will be available on all actions
*
* @module Models/actions
*/
"use strict";
const path = require("path");
const factory = require("./factory");
const utils = require(path.resolve(__dirname, "../lib/utils"));
const state = require(utils.getModulePath("lib/state"));
// Will be garbage-collected as soon as the definitive actions model will be
// created
const tempModel = factory.createModel("action");
const actions = Object.assign(tempModel, {
/**
* Perform an action
* Since actions are functions that interact with the universe they need
* two major references :
* - The State: which will allow them to interact with it
* - Other actions: so that actions composition can be possible
* To keep a clean, evolvable API, it is a best practice to communicate
* with objects (so they can be destructured at call and return).
* @param {String} id - Action name
* @param {Object} parameters - Action Parameters
* @return {Mixed} Action result
*/
performAction: (id, parameters) => tempModel
.getById(id)({
internals: {
state: state,
actions: tempModel.getAll()
},
parameters: parameters
})
});
actions.init({});
module.exports = actions;