Browse Source

Merge pull request #2674 from blink1073/services-examples-update

Update services readme and reinstate dist publish
Steven Silvester 7 years ago
parent
commit
bc75c0e214

+ 19 - 14
packages/services/README.md

@@ -120,17 +120,18 @@ Follow the package install instructions first.
 npm install --save xmlhttprequest ws
 ```
 
-Use `XMLHttpRequest` and `WebSocket` in the server settings (in ES6 syntax):
+Use `XMLHttpRequest` and `WebSocket` in the server settings (in ES5 syntax):
 
-```typescript
-import { Kernel, ServerConnection } from '@jupyterlab/services';
-import { XMLHttpRequest } from "xmlhttprequest";
-import { default as WebSocket } from 'ws';
+```javascript
+var services = require('@jupyterlab/services');
+var ws = require('ws');
+var xhr = require('xmlhttprequest');
 
 
-let serverSettings = ServerConnection.makeSettings({
-  xml: XMLHttpRequest,
-  webSocket: WebSocket
+// Set the request and socket functions.
+var serverSettings = services.ServerConnection.makeSettings({
+  xhrFactory: function () { return new xhr.XMLHttpRequest(); },
+  wsFactory: function (url, protocol) { return new ws(url, protocol); }
 });
 Kernel.startNew({ serverSettings }).then(...);
 ```
@@ -154,7 +155,7 @@ import {
 } from '@jupyterlab/services';
 
 
-/ Get a list of available kernels and connect to one.
+// Get a list of available kernels and connect to one.
 Kernel.listRunning().then(kernelModels => {
   Kernel.connectTo(kernelModels[0].id).then((kernel) => {
     console.log(kernel.name);
@@ -173,9 +174,9 @@ Kernel.getSpecs().then(kernelSpecs => {
   Kernel.startNew(options).then(kernel => {
     // Execute and handle replies.
     let future = kernel.requestExecute({ code: 'a = 1' } );
-    future.onDone = () => {
+    future.done.then(() => {
       console.log('Future is fulfilled');
-    };
+    });
     future.onIOPub = (msg) => {
       console.log(msg.content);  // Print rich output data.
     };
@@ -235,12 +236,12 @@ let options = {
 Session.startNew(options).then(session => {
   // Execute and handle replies on the kernel.
   let future = session.kernel.requestExecute({ code: 'a = 1' });
-  future.onDone = () => {
+  future.done.then(() => {
     console.log('Future is fulfilled');
-  };
+  });
 
   // Rename the session.
-  session.rename('/local/bar.ipynb').then(() => {
+  session.setPath('/local/bar.ipynb').then(() => {
     console.log('Session renamed to', session.path);
   });
 
@@ -262,6 +263,10 @@ Session.startNew(options).then(session => {
 
 ```typescript
 
+import {
+  Kernel
+} from '@jupyterlab/services';
+
 // Create a comm from the server side.
 //
 // Get info about the available kernels and connect to one.

+ 1 - 1
packages/services/examples/node/index.js

@@ -12,7 +12,7 @@ var xhr = require('xmlhttprequest');
 
 // Set the request and socket functions.
 var serverSettings = services.ServerConnection.makeSettings({
-  xhrFactory: function () { return new xhr.XMLHttpRequest() },
+  xhrFactory: function () { return new xhr.XMLHttpRequest(); },
   wsFactory: function (url, protocol) { return new ws(url, protocol); }
 });
 

+ 1 - 0
packages/services/package.json

@@ -32,6 +32,7 @@
     "build:src": "tsc --project src",
     "build:test": "tsc --project test/src",
     "build": "npm run build:src",
+    "prepublish": "npm run build:src && webpack",
     "test:coverage": "istanbul cover --dir test/coverage _mocha -- --retries 3 test/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json",
     "test:integration": "cd test && python integration_test.py",
     "test:devtool": "devtool node_modules/.bin/_mocha -qc test/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json --timeout=50000",