Skip to content

Commit

Permalink
[#96] Fix issues with module imports in Browser Environments
Browse files Browse the repository at this point in the history
- Issue with module imports failing is fixed with this.
- Polyfill Process.nextick issues fixed in browser context.
- Added both web and node.js examples in examples folder.
- Cleaned iup unwanted dependencies.
  • Loading branch information
mithunsatheesh authored and Mithun Satheesh committed Dec 13, 2020
1 parent f6dd06c commit 831f0e9
Show file tree
Hide file tree
Showing 13 changed files with 563 additions and 766 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"edge": "17",
"firefox": "60",
"chrome": "67",
"safari": "11.1",
"safari": "11.1"
},
"useBuiltIns": "usage",
"useBuiltIns": "usage"
}
]
]
Expand Down
2 changes: 1 addition & 1 deletion dist/node-rules.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var RuleEngine = require('../index');
var RuleEngine = require('../../index');
/* Sample Rule to block a transaction if its below 500 */
var rule = {
"condition": function(R) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var RuleEngine = require('../index');
var RuleEngine = require('../../index');
/* Set of Rules to be applied
First blocks a transaction if less than 500
Second blocks a debit card transaction.*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var RuleEngine = require('../index');
var RuleEngine = require('../../index');
/* Here we can see a rule which upon matching its condition,
does some processing and passes it to other rules for processing */
var rules = [{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var RuleEngine = require('../index');
var RuleEngine = require('../../index');
/* Set of Rules to be applied */
var rules = [{
"priority": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var RuleEngine = require('../index');
var RuleEngine = require('../../index');
/* Sample Rule to block a transaction if its below 500 */
var rule = {
"condition": function(R) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var colors = require('colors');
var RuleEngine = require('../index');
var RuleEngine = require('../../index');
var rules = [
/**** Rule 1 ****/
{
Expand Down
59 changes: 59 additions & 0 deletions examples/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Node Rules Web example</title>
<script src="../../dist/node-rules.min.js"></script>
</head>
<body>

<!--
==== READ THIS IF YOU ARE FINDING TROUBLE TO TO RUN THIS! ====
1. Install "Live Server" plugin on VS Code.
2. Right click on this file in the sidebar of Vs Code.
3. Choose open with Live Server option and bingo you are done.
-->

<script type="text/javascript">

/* Creating Rule Engine instance */
var R = new NodeRules();

/* Add a rule */
var rule = {
"condition": function(R) {
console.log(this);
R.when(this.transactionTotal < 500);
},
"consequence": function(R) {
this.result = false;
this.reason = "The transaction was blocked as it was less than 500";
R.stop();
}
};

/* Register Rule */
R.register(rule);

/* Add a Fact with less than 500 as transaction, and this should be blocked */
var fact = {
"name": "user4",
"application": "MOB2",
"transactionTotal": 400,
"cardType": "Credit Card"
};

/* Check if the engine blocks it! */
R.execute(fact, function (data) {
if (data.result) {
console.log("Valid transaction");
} else {
console.log("Blocked Reason:" + data.reason);
}
});

</script>

</body>
</html>
2 changes: 1 addition & 1 deletion lib/node-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
})(0);
};
RuleEngine.prototype.nextTick = function(callbackFn) {
if (process && process.nextTick) {
if (typeof process !== 'undefined' && process.nextTick) {
process.nextTick(callbackFn);
} else {
setTimeout(callbackFn, 0);
Expand Down
Loading

0 comments on commit 831f0e9

Please sign in to comment.