Skip to content

Commit 831f0e9

Browse files
mithunsatheeshMithun Satheesh
authored and
Mithun Satheesh
committed
[#96] Fix issues with module imports in Browser Environments
- 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.
1 parent f6dd06c commit 831f0e9

13 files changed

+563
-766
lines changed

.babelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"edge": "17",
88
"firefox": "60",
99
"chrome": "67",
10-
"safari": "11.1",
10+
"safari": "11.1"
1111
},
12-
"useBuiltIns": "usage",
12+
"useBuiltIns": "usage"
1313
}
1414
]
1515
]

dist/node-rules.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/1.SimpleRule.js renamed to examples/node.js/1.SimpleRule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var RuleEngine = require('../index');
1+
var RuleEngine = require('../../index');
22
/* Sample Rule to block a transaction if its below 500 */
33
var rule = {
44
"condition": function(R) {

examples/2.MultipleRules.js renamed to examples/node.js/2.MultipleRules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var RuleEngine = require('../index');
1+
var RuleEngine = require('../../index');
22
/* Set of Rules to be applied
33
First blocks a transaction if less than 500
44
Second blocks a debit card transaction.*/

examples/3.CascadingRules.js renamed to examples/node.js/3.CascadingRules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var RuleEngine = require('../index');
1+
var RuleEngine = require('../../index');
22
/* Here we can see a rule which upon matching its condition,
33
does some processing and passes it to other rules for processing */
44
var rules = [{

examples/4.PrioritizedRules.js renamed to examples/node.js/4.PrioritizedRules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var RuleEngine = require('../index');
1+
var RuleEngine = require('../../index');
22
/* Set of Rules to be applied */
33
var rules = [{
44
"priority": 4,

examples/5.RecurssionWithRules.js renamed to examples/node.js/5.RecurssionWithRules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var RuleEngine = require('../index');
1+
var RuleEngine = require('../../index');
22
/* Sample Rule to block a transaction if its below 500 */
33
var rule = {
44
"condition": function(R) {

examples/6.MoreRulesAndFacts.js renamed to examples/node.js/6.MoreRulesAndFacts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var colors = require('colors');
2-
var RuleEngine = require('../index');
2+
var RuleEngine = require('../../index');
33
var rules = [
44
/**** Rule 1 ****/
55
{

examples/web/index.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Node Rules Web example</title>
7+
<script src="../../dist/node-rules.min.js"></script>
8+
</head>
9+
<body>
10+
11+
<!--
12+
==== READ THIS IF YOU ARE FINDING TROUBLE TO TO RUN THIS! ====
13+
1. Install "Live Server" plugin on VS Code.
14+
2. Right click on this file in the sidebar of Vs Code.
15+
3. Choose open with Live Server option and bingo you are done.
16+
-->
17+
18+
<script type="text/javascript">
19+
20+
/* Creating Rule Engine instance */
21+
var R = new NodeRules();
22+
23+
/* Add a rule */
24+
var rule = {
25+
"condition": function(R) {
26+
console.log(this);
27+
R.when(this.transactionTotal < 500);
28+
},
29+
"consequence": function(R) {
30+
this.result = false;
31+
this.reason = "The transaction was blocked as it was less than 500";
32+
R.stop();
33+
}
34+
};
35+
36+
/* Register Rule */
37+
R.register(rule);
38+
39+
/* Add a Fact with less than 500 as transaction, and this should be blocked */
40+
var fact = {
41+
"name": "user4",
42+
"application": "MOB2",
43+
"transactionTotal": 400,
44+
"cardType": "Credit Card"
45+
};
46+
47+
/* Check if the engine blocks it! */
48+
R.execute(fact, function (data) {
49+
if (data.result) {
50+
console.log("Valid transaction");
51+
} else {
52+
console.log("Blocked Reason:" + data.reason);
53+
}
54+
});
55+
56+
</script>
57+
58+
</body>
59+
</html>

lib/node-rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
})(0);
106106
};
107107
RuleEngine.prototype.nextTick = function(callbackFn) {
108-
if (process && process.nextTick) {
108+
if (typeof process !== 'undefined' && process.nextTick) {
109109
process.nextTick(callbackFn);
110110
} else {
111111
setTimeout(callbackFn, 0);

0 commit comments

Comments
 (0)