Socket
Socket
Sign inDemoInstall

nogap

Package Overview
Dependencies
39
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.5 to 0.1.6

samples/Assets/Assets.js

2

package.json
{
"name": "nogap",
"version": "0.1.5",
"version": "0.1.6",
"author": {

@@ -5,0 +5,0 @@ "name": "Dominik Seifert",

@@ -26,3 +26,3 @@ NoGap

[Samples](samples)
[Samples](samples)<a name="samples"></a>
=============

@@ -137,24 +137,84 @@

## [CodeSharingWithBase](samples/CodeSharingWithBase)
## [CodeSharingValidation](samples/CodeSharingValidation)
```js
tellClientSomething: function() {
this.Tools.keepOpen();
Base: NoGapDef.defBase(function(SharedTools, Shared, SharedContext) { return {
validateText: function(text) {
if (text.indexOf('a') >= 0 || text.indexOf('A') >= 0) {
return null;
}
return text.trim();
}
};}),
// wait 500 milliseconds before replying
setTimeout(function() {
this.client.showHostMessage('We have exchanged ' + ++iAttempt + ' messages.');
this.Tools.flush();
}.bind(this), 500);
}
Host: NoGapDef.defHost(function(SharedTools, Shared, SharedContext) { return {
Public: {
setValue: function(value) {
this.value = this.Shared.validateText(value);
// ...
}
}
};}),
Client: NoGapDef.defClient(function(Tools, Instance, Context) { return {
// ...
value = this.validateText(value);
// ...
};})
```
### New Concepts
* We need to perform an asynchronous request whose result is to be sent to the other side:
* In that case, first call `this.Tools.keepOpen()`, so the client connection will not be closed automatically
* Once you sent everything to the client, call `this.Tools.flush()`
* The `Base` definition is merged into both `Client` and `Host`
* You can use it to easily share code between them
## [Assets](samples/Assets)
```js
NoGapDef.component({
Host: NoGapDef.defHost(function(SharedTools, Shared, SharedContext) { return {
Assets: {
AutoIncludes: {
js: [
// jquery
'//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
],
css: [
// bootstrap
'//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css'
]
},
Files: {
string: {
view: 'template.html'
}
}
}
};}),
Client: NoGapDef.defClient(function(Tools, Instance, Context) { return {
initClient: function() {
document.body.innerHTML += this.assets.view;
}
};})
});
```
### New Concepts
* So far, you can define two types of file-based assets:
* `AutoIncludes` defines lists of `js` and `css` files that will be automatically included in the client header
* `Files` will be read and it's contents will be available through the clients `assets` variable.
* Currently they can only be interpreted as string. Future plans: `code`, `image` and more more more...
## [Dynamic Loading of Components](samples/DynamicallyLoadedComponents)
TODO: Not done yet...
<a name="getting_started"></a>Getting Started

@@ -164,3 +224,3 @@ =============

This tutorial is aimed at those who are new to `NoGap`, and new to `Node` in general.
It should help you bridge the gap from the [Code Snippets](#code_snippets) to a real-world application.
It should help you bridge the gap from the [Code Snippets](#samples) to a real-world application.

@@ -192,3 +252,3 @@ ## Recommended File Structure

Check out <a href="https://www.npmjs.org/">https://www.npmjs.org/</a> to see all available modules.
Check out [NPM JS]("https://www.npmjs.org/") to see all available modules.

@@ -199,4 +259,5 @@

This folder contains your `NoGap` components, and possibly (some of) their assets. You can name it anything you want.
NOTE: Placing assets (such as *.html templates, stylesheets, images etc.) next to code is actually good style, if it supports modularization.
If your components are mostly self-contained, you can easily move their whole folder, including their assets, to deploy them in other places.
If your components have a sufficiently modular design, you can simply copy their folder, to deploy them and their assets in other places.

@@ -247,11 +308,11 @@

1. Setup your app
2. Start your <a href="http://expressjs.com/4x/api.html">`express` server</a>
2. Start `NoGap`
3. Start your [`express` server](http://expressjs.com/4x/api.html)
Express is the standard Node way of starting a web server and let clients connect.
Express is the standard Node way of starting a HTTP server and let clients connect.
Once it is running you can connect to it with your browser on the specified port.
NOTE: When using `NoGap` you will not need to work with express anymore. You can, but you are recommended to use components instead.
With `NoGap`, we add one more job to it:
With that in mind, you are recommended to take a look at the [`NoGap Sample App`](samples/sample_app) to look at a slightly more complete example of using `NoGap`.
1. Setup your app
2. Initialize `NoGap`
3. Start your <a href="http://expressjs.com/4x/api.html">`express` server</a>
In case of questions, feel free to contact me.

@@ -8,3 +8,3 @@ /**

// ##########################################################################
// Define TwoWayStreet component
// Define CodeSharingValidation component

@@ -11,0 +11,0 @@ var NoGapDef = require('nogap').Def;

@@ -8,3 +8,3 @@ /**

// ##########################################################################
// Define TwoWayStreet component
// Define TwoWayStreetAsync component

@@ -11,0 +11,0 @@ var NoGapDef = require('nogap').Def;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc