Browse Source

Added new nonbundle example

Luis Figueiredo 8 years ago
parent
commit
cab8acfdbc
2 changed files with 32 additions and 1 deletions
  1. 20 1
      README.md
  2. 12 0
      test/hci-usecase/bundles/nonbundle-test/index.js

+ 20 - 1
README.md

@@ -4,7 +4,26 @@ hci
 Introduction:
 ---------------
 Researching a way to bring java alike OSGi to nodejs for hot swappable modules.   
-This is not an intention to replace nodejs modules but a way to swap certain areas of the application such as bringing new versions without a restart
+This is not an intention to replace nodejs modules but a way to swap certain areas of the application such as bringing new versions without a restart     
+Bundles will communicate with each others using events as shown in examples    
+Node modules can be added and updated they will be exported/used as:
+
+Since as osgi there is no order on module loading, with context.with we do the callback just when we have the module, else it will be ignored
+the goal is to keep module always running independent, in case module depends on other module to perform its main operation, it can always return an error instead of not working at all
+
+```javascript
+	// using node modules as bundles:
+	var activator = {
+		start(context) {
+			context.setInterval(() => {  // using context.setInterval it will automatically clearInterval on bundle stop
+				context.with(['prettyjson'],(prettyjson) => {
+					prettyjson.render({test: 'test'})			
+				})
+			},3000)
+		}
+	}
+
+```
 
 Usage:
 -------

+ 12 - 0
test/hci-usecase/bundles/nonbundle-test/index.js

@@ -0,0 +1,12 @@
+var log =require('hlogger').createLogger('nonbundle-test')
+// using node modules as bundles:
+var activator = {
+	start(context) {
+		context.setInterval(() => {
+			context.with(['prettyjson'],(prettyjson) => {
+				log.info(prettyjson.render({test:'test'}))
+			})
+		},3000)
+	}
+}
+module.exports.bundleActivator = activator