From d442b7057af0e94e370f9ef36ad9378af2a14f95 Mon Sep 17 00:00:00 2001 From: James McDonald <15jgm4@queensu.ca> Date: Sat, 12 Oct 2019 14:12:43 -0400 Subject: [PATCH 1/4] created initial web demo layout --- DemoApp/.vscode/settings.json | 3 ++ DemoApp/resources/css/app.css | 0 DemoApp/resources/js/memory.js | 92 ++++++++++++++++++++++++++++++++++ DemoApp/src/index.html | 7 +++ 4 files changed, 102 insertions(+) create mode 100644 DemoApp/.vscode/settings.json create mode 100644 DemoApp/resources/css/app.css create mode 100644 DemoApp/resources/js/memory.js create mode 100644 DemoApp/src/index.html diff --git a/DemoApp/.vscode/settings.json b/DemoApp/.vscode/settings.json new file mode 100644 index 0000000..3b66410 --- /dev/null +++ b/DemoApp/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "git.ignoreLimitWarning": true +} \ No newline at end of file diff --git a/DemoApp/resources/css/app.css b/DemoApp/resources/css/app.css new file mode 100644 index 0000000..e69de29 diff --git a/DemoApp/resources/js/memory.js b/DemoApp/resources/js/memory.js new file mode 100644 index 0000000..c72813b --- /dev/null +++ b/DemoApp/resources/js/memory.js @@ -0,0 +1,92 @@ +var memoryJS = { + name: 'A memoryJS base global scoped object' +} + +class Pointer { + constructor (address = '0' /* address string */, local = false) { + var _value = address + var _local = local + this.isLocal = function () { + return _local + } + this.value = function () { + return _value + } + } + + pointedTo (MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */) { + if (this.isLocal()) { + return MemoryObj.valueOf(this.value()) + } else { + return memoryJS.publicMemoryObj.valueOf(this.value()) + } + } + + changeValue (object, MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */) { + if (this.isLocal()) { + MemoryObj.changeValue(this.value(), object) + } else { + memoryJS.publicMemoryObj.changeValue(this.value(), object) + } + return 0 + } + + free (MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */) { + if (this.isLocal()) { + MemoryObj.free(this.value()) + } else { + memoryJS.publicMemoryObj.free() + } + return null + } + + set point (object) { + if (this.isLocal()) { + throw new Error('Pointer.point shorthand is only applicable for global pointers. Use changeValue() function instead') + } else { + this.changeValue(object) + } + } + + get point () { + if (this.isLocal()) { + throw new Error('Pointer.point shorthand is only applicable for global pointers. Use pointedTo() function instead') + } else { + return this.pointedTo() + } + } +} + +class Memory { + constructor (global = false) { + var _endaddr = 0 + var _objbook = [] + this.newobj = function (object /* object */) { + _objbook.push(object) + _endaddr = _endaddr + 1 + if (global) { + return new Pointer((_endaddr - 1).toString(36)) + } else { + return new Pointer((_endaddr - 1).toString(36), true) + } + } + + this.valueOf = function (address = '0' /* string */) { + return _objbook[parseInt(address, 36)] + } + + this.changeValue = function (address, object) { + _objbook[parseInt(address, 36)] = object + return 0 + } + + this.free = function (address = '0' /* string */) { + _objbook[parseInt(address, 36)] = null + return 0 + } + + this.nullptr = this.newobj(null) + } +} + +memoryJS.publicMemoryObj = new Memory(true) diff --git a/DemoApp/src/index.html b/DemoApp/src/index.html new file mode 100644 index 0000000..8f322fd --- /dev/null +++ b/DemoApp/src/index.html @@ -0,0 +1,7 @@ + + +
+&*j;=u%25ay-%>3@81tGe^_z*C7pb9y*Ed^H3t$BIKH2o+olp#$q;)_ zfpjCb_^VFg5fU~K)nf*d*r@BCC>UZ!0&b?AGk_jTPXaSnCuW110wjHPPe^9R^;jo3 zwvzTl)C`Zl5}O2}3lec=hZ*$JnkW#7enKKc)(pM${_$9Hc=Sr_A9Biwe*Y=T?~1CK z6eZ9uPICjy-sMGbZl$yQmpB&`ouS8v{58__t0$JP%i3R&%QR3ianbZqDs<2#5FdN@n5bCn^ZtH992~5k(eA|8|@G9u`wdn7bnpg|@{m z^d6Y`*$Zf2Xr&|g%sai#5}Syvv(>Jnx&EM7-|Jr7!M~zdAyjt*xl;OLhvW-a%H1m0 z*x5*nb=R5u><7lyVpN AR?q@1U59 zO+)QW wL8t zyip?u_nI+K$uh{ y)~}qj?(w0&=SE^8`_WMM zTybjG=999h38Yes7}-4*LJ7H)UE8{mE(6;8voE+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00001 diff --git a/demoApp/public/manifest.json b/demoApp/public/manifest.json new file mode 100644 index 0000000..e4c94e6 --- /dev/null +++ b/demoApp/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/demoApp/public/robots.txt b/demoApp/public/robots.txt new file mode 100644 index 0000000..01b0f9a --- /dev/null +++ b/demoApp/public/robots.txt @@ -0,0 +1,2 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * diff --git a/demoApp/src/App.css b/demoApp/src/App.css new file mode 100644 index 0000000..b41d297 --- /dev/null +++ b/demoApp/src/App.css @@ -0,0 +1,33 @@ +.App { + text-align: center; +} + +.App-logo { + animation: App-logo-spin infinite 20s linear; + height: 40vmin; + pointer-events: none; +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/demoApp/src/App.js b/demoApp/src/App.js new file mode 100644 index 0000000..65d8dc7 --- /dev/null +++ b/demoApp/src/App.js @@ -0,0 +1,15 @@ +import * as utils from "./memory.js"; +import React from "react"; +import logo from "./logo.svg"; +import Demo from "./components/Demo"; +import "./App.css"; + +function App() { + return ( + ++ ); +} + +export default App; diff --git a/demoApp/src/App.test.js b/demoApp/src/App.test.js new file mode 100644 index 0000000..a754b20 --- /dev/null +++ b/demoApp/src/App.test.js @@ -0,0 +1,9 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import App from './App'; + +it('renders without crashing', () => { + const div = document.createElement('div'); + ReactDOM.render(+ , div); + ReactDOM.unmountComponentAtNode(div); +}); diff --git a/demoApp/src/components/Demo.js b/demoApp/src/components/Demo.js new file mode 100644 index 0000000..6fb9424 --- /dev/null +++ b/demoApp/src/components/Demo.js @@ -0,0 +1,38 @@ +import * as utils from "../memory.js"; +import React from "react"; + +export default class Demo extends React.Component { + constructor(props) { + super(props); + this.state = { + ptr: "" + }; + + this.handlePtrCreate = this.handlePtrCreate.bind(this); + this.handlePtrCreateChange = this.handlePtrCreateChange.bind(this); + } + handlePtrCreate(event) {} + handlePtrCreateChange(event) {} + + handl; + createPoint() { + var j = utils.publicMemoryObj.newObj(56); + } + + render() { + return ( + + ++ ); + } +} diff --git a/demoApp/src/index.css b/demoApp/src/index.css new file mode 100644 index 0000000..4a1df4d --- /dev/null +++ b/demoApp/src/index.css @@ -0,0 +1,13 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", + "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", + monospace; +} diff --git a/demoApp/src/index.js b/demoApp/src/index.js new file mode 100644 index 0000000..87d1be5 --- /dev/null +++ b/demoApp/src/index.js @@ -0,0 +1,12 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import * as serviceWorker from './serviceWorker'; + +ReactDOM.render(, document.getElementById('root')); + +// If you want your app to work offline and load faster, you can change +// unregister() to register() below. Note this comes with some pitfalls. +// Learn more about service workers: https://bit.ly/CRA-PWA +serviceWorker.unregister(); diff --git a/demoApp/src/logo.svg b/demoApp/src/logo.svg new file mode 100644 index 0000000..6b60c10 --- /dev/null +++ b/demoApp/src/logo.svg @@ -0,0 +1,7 @@ + diff --git a/demoApp/src/memory.js b/demoApp/src/memory.js new file mode 100644 index 0000000..c72813b --- /dev/null +++ b/demoApp/src/memory.js @@ -0,0 +1,92 @@ +var memoryJS = { + name: 'A memoryJS base global scoped object' +} + +class Pointer { + constructor (address = '0' /* address string */, local = false) { + var _value = address + var _local = local + this.isLocal = function () { + return _local + } + this.value = function () { + return _value + } + } + + pointedTo (MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */) { + if (this.isLocal()) { + return MemoryObj.valueOf(this.value()) + } else { + return memoryJS.publicMemoryObj.valueOf(this.value()) + } + } + + changeValue (object, MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */) { + if (this.isLocal()) { + MemoryObj.changeValue(this.value(), object) + } else { + memoryJS.publicMemoryObj.changeValue(this.value(), object) + } + return 0 + } + + free (MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */) { + if (this.isLocal()) { + MemoryObj.free(this.value()) + } else { + memoryJS.publicMemoryObj.free() + } + return null + } + + set point (object) { + if (this.isLocal()) { + throw new Error('Pointer.point shorthand is only applicable for global pointers. Use changeValue() function instead') + } else { + this.changeValue(object) + } + } + + get point () { + if (this.isLocal()) { + throw new Error('Pointer.point shorthand is only applicable for global pointers. Use pointedTo() function instead') + } else { + return this.pointedTo() + } + } +} + +class Memory { + constructor (global = false) { + var _endaddr = 0 + var _objbook = [] + this.newobj = function (object /* object */) { + _objbook.push(object) + _endaddr = _endaddr + 1 + if (global) { + return new Pointer((_endaddr - 1).toString(36)) + } else { + return new Pointer((_endaddr - 1).toString(36), true) + } + } + + this.valueOf = function (address = '0' /* string */) { + return _objbook[parseInt(address, 36)] + } + + this.changeValue = function (address, object) { + _objbook[parseInt(address, 36)] = object + return 0 + } + + this.free = function (address = '0' /* string */) { + _objbook[parseInt(address, 36)] = null + return 0 + } + + this.nullptr = this.newobj(null) + } +} + +memoryJS.publicMemoryObj = new Memory(true) diff --git a/demoApp/src/serviceWorker.js b/demoApp/src/serviceWorker.js new file mode 100644 index 0000000..f8c7e50 --- /dev/null +++ b/demoApp/src/serviceWorker.js @@ -0,0 +1,135 @@ +// This optional code is used to register a service worker. +// register() is not called by default. + +// This lets the app load faster on subsequent visits in production, and gives +// it offline capabilities. However, it also means that developers (and users) +// will only see deployed updates on subsequent visits to a page, after all the +// existing tabs open on the page have been closed, since previously cached +// resources are updated in the background. + +// To learn more about the benefits of this model and instructions on how to +// opt-in, read https://bit.ly/CRA-PWA + +const isLocalhost = Boolean( + window.location.hostname === 'localhost' || + // [::1] is the IPv6 localhost address. + window.location.hostname === '[::1]' || + // 127.0.0.1/8 is considered localhost for IPv4. + window.location.hostname.match( + /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ + ) +); + +export function register(config) { + if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { + // The URL constructor is available in all browsers that support SW. + const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); + if (publicUrl.origin !== window.location.origin) { + // Our service worker won't work if PUBLIC_URL is on a different origin + // from what our page is served on. This might happen if a CDN is used to + // serve assets; see https://github.com/facebook/create-react-app/issues/2374 + return; + } + + window.addEventListener('load', () => { + const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; + + if (isLocalhost) { + // This is running on localhost. Let's check if a service worker still exists or not. + checkValidServiceWorker(swUrl, config); + + // Add some additional logging to localhost, pointing developers to the + // service worker/PWA documentation. + navigator.serviceWorker.ready.then(() => { + console.log( + 'This web app is being served cache-first by a service ' + + 'worker. To learn more, visit https://bit.ly/CRA-PWA' + ); + }); + } else { + // Is not localhost. Just register service worker + registerValidSW(swUrl, config); + } + }); + } +} + +function registerValidSW(swUrl, config) { + navigator.serviceWorker + .register(swUrl) + .then(registration => { + registration.onupdatefound = () => { + const installingWorker = registration.installing; + if (installingWorker == null) { + return; + } + installingWorker.onstatechange = () => { + if (installingWorker.state === 'installed') { + if (navigator.serviceWorker.controller) { + // At this point, the updated precached content has been fetched, + // but the previous service worker will still serve the older + // content until all client tabs are closed. + console.log( + 'New content is available and will be used when all ' + + 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' + ); + + // Execute callback + if (config && config.onUpdate) { + config.onUpdate(registration); + } + } else { + // At this point, everything has been precached. + // It's the perfect time to display a + // "Content is cached for offline use." message. + console.log('Content is cached for offline use.'); + + // Execute callback + if (config && config.onSuccess) { + config.onSuccess(registration); + } + } + } + }; + }; + }) + .catch(error => { + console.error('Error during service worker registration:', error); + }); +} + +function checkValidServiceWorker(swUrl, config) { + // Check if the service worker can be found. If it can't reload the page. + fetch(swUrl) + .then(response => { + // Ensure service worker exists, and that we really are getting a JS file. + const contentType = response.headers.get('content-type'); + if ( + response.status === 404 || + (contentType != null && contentType.indexOf('javascript') === -1) + ) { + // No service worker found. Probably a different app. Reload the page. + navigator.serviceWorker.ready.then(registration => { + registration.unregister().then(() => { + window.location.reload(); + }); + }); + } else { + // Service worker found. Proceed as normal. + registerValidSW(swUrl, config); + } + }) + .catch(() => { + console.log( + 'No internet connection found. App is running in offline mode.' + ); + }); +} + +export function unregister() { + if ('serviceWorker' in navigator) { + navigator.serviceWorker.ready.then(registration => { + registration.unregister(); + }); + } +} From ed1fcc1a48721c7d66e7623a3a15e45598ce3d02 Mon Sep 17 00:00:00 2001 From: James McDonald <15jgm4@queensu.ca> Date: Tue, 15 Oct 2019 21:10:05 -0400 Subject: [PATCH 3/4] Created basic react app with placeholders --- demoApp/src/App.js | 1 - demoApp/src/ReactMemory.js | 103 ++++++++++++++++++++++ demoApp/src/components/Demo.js | 152 ++++++++++++++++++++++++++++----- demoApp/src/memory.js | 92 -------------------- 4 files changed, 233 insertions(+), 115 deletions(-) create mode 100644 demoApp/src/ReactMemory.js delete mode 100644 demoApp/src/memory.js diff --git a/demoApp/src/App.js b/demoApp/src/App.js index 65d8dc7..330e366 100644 --- a/demoApp/src/App.js +++ b/demoApp/src/App.js @@ -1,4 +1,3 @@ -import * as utils from "./memory.js"; import React from "react"; import logo from "./logo.svg"; import Demo from "./components/Demo"; diff --git a/demoApp/src/ReactMemory.js b/demoApp/src/ReactMemory.js new file mode 100644 index 0000000..74f3d1c --- /dev/null +++ b/demoApp/src/ReactMemory.js @@ -0,0 +1,103 @@ +var memoryJS = { + name: "A memoryJS base global scoped object" +}; + +export class Pointer { + constructor(address = "0" /* address string */, local = false) { + var _value = address; + var _local = local; + this.isLocal = function() { + return _local; + }; + this.value = function() { + return _value; + }; + } + + pointedTo( + MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */ + ) { + if (this.isLocal()) { + return MemoryObj.valueOf(this.value()); + } else { + return memoryJS.publicMemoryObj.valueOf(this.value()); + } + } + + changeValue( + object, + MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */ + ) { + if (this.isLocal()) { + MemoryObj.changeValue(this.value(), object); + } else { + memoryJS.publicMemoryObj.changeValue(this.value(), object); + } + return 0; + } + + free( + MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */ + ) { + if (this.isLocal()) { + MemoryObj.free(this.value()); + } else { + memoryJS.publicMemoryObj.free(); + } + return null; + } + + set point(object) { + if (this.isLocal()) { + throw new Error( + "Pointer.point shorthand is only applicable for global pointers. Use changeValue() function instead" + ); + } else { + this.changeValue(object); + } + } + + get point() { + if (this.isLocal()) { + throw new Error( + "Pointer.point shorthand is only applicable for global pointers. Use pointedTo() function instead" + ); + } else { + return this.pointedTo(); + } + } +} + +export class Memory { + constructor(global = false) { + var _endaddr = 0; + var _objbook = []; + this.newobj = function(object /* object */) { + _objbook.push(object); + _endaddr = _endaddr + 1; + if (global) { + return new Pointer((_endaddr - 1).toString(36)); + } else { + return new Pointer((_endaddr - 1).toString(36), true); + } + }; + + this.valueOf = function(address = "0" /* string */) { + return _objbook[parseInt(address, 36)]; + }; + + this.changeValue = function(address, object) { + _objbook[parseInt(address, 36)] = object; + return 0; + }; + + this.free = function(address = "0" /* string */) { + _objbook[parseInt(address, 36)] = null; + return 0; + }; + + this.nullptr = this.newobj(null); + } +} + +memoryJS.publicMemoryObj = new Memory(true); diff --git a/demoApp/src/components/Demo.js b/demoApp/src/components/Demo.js index 6fb9424..6bce7f3 100644 --- a/demoApp/src/components/Demo.js +++ b/demoApp/src/components/Demo.js @@ -1,38 +1,146 @@ -import * as utils from "../memory.js"; +import * as memoryJS from "../ReactMemory.js"; import React from "react"; export default class Demo extends React.Component { constructor(props) { super(props); this.state = { - ptr: "" + ptrInput: "", + ptr: "", + ptrCreated: false, + customMemInput: "", + customMem: "" }; this.handlePtrCreate = this.handlePtrCreate.bind(this); - this.handlePtrCreateChange = this.handlePtrCreateChange.bind(this); + this.handleInputChange = this.handleInputChange.bind(this); + this.deletePtr = this.deletePtr.bind(this); + this.changeCustomMem = this.changeCustomMem.bind(this); } - handlePtrCreate(event) {} - handlePtrCreateChange(event) {} - handl; - createPoint() { - var j = utils.publicMemoryObj.newObj(56); + handlePtrCreate(event) { + console.log("reached"); + // var pointer = memoryJS.Pointer.publicMemoryObj.newObj(255); + + //Instead set ptr state var to be equal to a pointer to an object of value passed in. + + var pointer = this.state.ptrInput; + this.setState({ ptr: pointer, ptrCreated: true }); + event.preventDefault(); + } + + handleInputChange(event) { + const target = event.target; + const value = target.value; + const name = target.name; + + this.setState({ + [name]: value + }); + } + + deletePtr(event) { + this.setState({ ptr: "", ptrCreated: true }); + event.preventDefault(); + } + + changeCustomMem(event) { + // create a new pointer at specific mem location + + this.setState({ customMem: this.state.customMemInput }); + alert("New pointer was created pointing to " + this.state.customMem); + event.preventDefault(); } render() { - return ( - - -- ); + if (!this.state.ptrCreated) { + return ( ++ ++ ); + } else { + return ( ++ {/*
+ ); + } } } diff --git a/demoApp/src/memory.js b/demoApp/src/memory.js deleted file mode 100644 index c72813b..0000000 --- a/demoApp/src/memory.js +++ /dev/null @@ -1,92 +0,0 @@ -var memoryJS = { - name: 'A memoryJS base global scoped object' -} - -class Pointer { - constructor (address = '0' /* address string */, local = false) { - var _value = address - var _local = local - this.isLocal = function () { - return _local - } - this.value = function () { - return _value - } - } - - pointedTo (MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */) { - if (this.isLocal()) { - return MemoryObj.valueOf(this.value()) - } else { - return memoryJS.publicMemoryObj.valueOf(this.value()) - } - } - - changeValue (object, MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */) { - if (this.isLocal()) { - MemoryObj.changeValue(this.value(), object) - } else { - memoryJS.publicMemoryObj.changeValue(this.value(), object) - } - return 0 - } - - free (MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */) { - if (this.isLocal()) { - MemoryObj.free(this.value()) - } else { - memoryJS.publicMemoryObj.free() - } - return null - } - - set point (object) { - if (this.isLocal()) { - throw new Error('Pointer.point shorthand is only applicable for global pointers. Use changeValue() function instead') - } else { - this.changeValue(object) - } - } - - get point () { - if (this.isLocal()) { - throw new Error('Pointer.point shorthand is only applicable for global pointers. Use pointedTo() function instead') - } else { - return this.pointedTo() - } - } -} - -class Memory { - constructor (global = false) { - var _endaddr = 0 - var _objbook = [] - this.newobj = function (object /* object */) { - _objbook.push(object) - _endaddr = _endaddr + 1 - if (global) { - return new Pointer((_endaddr - 1).toString(36)) - } else { - return new Pointer((_endaddr - 1).toString(36), true) - } - } - - this.valueOf = function (address = '0' /* string */) { - return _objbook[parseInt(address, 36)] - } - - this.changeValue = function (address, object) { - _objbook[parseInt(address, 36)] = object - return 0 - } - - this.free = function (address = '0' /* string */) { - _objbook[parseInt(address, 36)] = null - return 0 - } - - this.nullptr = this.newobj(null) - } -} - -memoryJS.publicMemoryObj = new Memory(true) From 69423e90a4a5262b9f8a9147de15295afd3b1e6b Mon Sep 17 00:00:00 2001 From: James McDonald <15jgm4@queensu.ca> Date: Wed, 16 Oct 2019 22:27:00 -0400 Subject: [PATCH 4/4] fixed pr tests from failing --- demoApp/package-lock.json | 193 ++++++++++++++++++++++++++++++++- demoApp/package.json | 3 + demoApp/src/App.js | 15 ++- demoApp/src/App.test.js | 14 +-- demoApp/src/ReactMemory.js | 104 +++++++++--------- demoApp/src/components/Demo.js | 98 ++++++++--------- demoApp/src/index.js | 14 +-- demoApp/src/serviceWorker.js | 64 +++++------ 8 files changed, 347 insertions(+), 158 deletions(-) diff --git a/demoApp/package-lock.json b/demoApp/package-lock.json index e273070..aec773c 100644 --- a/demoApp/package-lock.json +++ b/demoApp/package-lock.json @@ -4001,6 +4001,12 @@ "ms": "^2.1.1" } }, + "debug-log": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/debug-log/-/debug-log-1.0.1.tgz", + "integrity": "sha1-IwdjLUwEOCuN+KMvcLiVBG1SdF8=", + "dev": true + }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", @@ -4088,6 +4094,28 @@ } } }, + "deglob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/deglob/-/deglob-4.0.1.tgz", + "integrity": "sha512-/g+RDZ7yf2HvoW+E5Cy+K94YhgcFgr6C8LuHZD1O5HoNPkf3KY6RfXJ0DBGlB/NkLi5gml+G9zqRzk9S0mHZCg==", + "dev": true, + "requires": { + "find-root": "^1.0.0", + "glob": "^7.0.5", + "ignore": "^5.0.0", + "pkg-config": "^1.1.0", + "run-parallel": "^1.1.2", + "uniq": "^1.0.1" + }, + "dependencies": { + "ignore": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.4.tgz", + "integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==", + "dev": true + } + } + }, "del": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/del/-/del-3.0.0.tgz", @@ -4606,6 +4634,18 @@ "confusing-browser-globals": "^1.0.8" } }, + "eslint-config-standard": { + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-14.1.0.tgz", + "integrity": "sha512-EF6XkrrGVbvv8hL/kYa/m6vnvmUT+K82pJJc4JJVMM6+Qgqh0pnwprSxdduDLB9p/7bIxD+YV5O0wfb8lmcPbA==", + "dev": true + }, + "eslint-config-standard-jsx": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-standard-jsx/-/eslint-config-standard-jsx-8.1.0.tgz", + "integrity": "sha512-ULVC8qH8qCqbU792ZOO6DaiaZyHNS/5CZt3hKqHkEhVlhPEPN3nfBqqxJCyp59XrjIBZPu1chMYe9T2DXZ7TMw==", + "dev": true + }, "eslint-import-resolver-node": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz", @@ -4712,6 +4752,24 @@ } } }, + "eslint-plugin-es": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-2.0.0.tgz", + "integrity": "sha512-f6fceVtg27BR02EYnBhgWLFQfK6bN4Ll0nQFrBHOlCsAyxeZkn0NHns5O0YZOPrV1B3ramd6cgFwaoFLcSkwEQ==", + "dev": true, + "requires": { + "eslint-utils": "^1.4.2", + "regexpp": "^3.0.0" + }, + "dependencies": { + "regexpp": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.0.0.tgz", + "integrity": "sha512-Z+hNr7RAVWxznLPuA7DIh8UNX1j9CDrUQxskw9IrBE1Dxue2lyXT+shqEIeLUjrokxIP8CMy1WkjgG3rTsd5/g==", + "dev": true + } + } + }, "eslint-plugin-flowtype": { "version": "3.13.0", "resolved": "https://registry.npmjs.org/eslint-plugin-flowtype/-/eslint-plugin-flowtype-3.13.0.tgz", @@ -4867,6 +4925,34 @@ "jsx-ast-utils": "^2.2.1" } }, + "eslint-plugin-node": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-10.0.0.tgz", + "integrity": "sha512-1CSyM/QCjs6PXaT18+zuAXsjXGIGo5Rw630rSKwokSs2jrYURQc4R5JZpoanNCqwNmepg+0eZ9L7YiRUJb8jiQ==", + "dev": true, + "requires": { + "eslint-plugin-es": "^2.0.0", + "eslint-utils": "^1.4.2", + "ignore": "^5.1.1", + "minimatch": "^3.0.4", + "resolve": "^1.10.1", + "semver": "^6.1.0" + }, + "dependencies": { + "ignore": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.4.tgz", + "integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==", + "dev": true + } + } + }, + "eslint-plugin-promise": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-4.2.1.tgz", + "integrity": "sha512-VoM09vT7bfA7D+upt+FjeBO5eHIJQBUWki1aPvB+vbNiHS3+oGIJGIeyBtKQTME6UPXXy3vV07OL1tHd3ANuDw==", + "dev": true + }, "eslint-plugin-react": { "version": "7.14.3", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.14.3.tgz", @@ -4898,6 +4984,12 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-1.7.0.tgz", "integrity": "sha512-iXTCFcOmlWvw4+TOE8CLWj6yX1GwzT0Y6cUfHHZqWnSk144VmVIRcVGtUAzrLES7C798lmvnt02C7rxaOX1HNA==" }, + "eslint-plugin-standard": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-standard/-/eslint-plugin-standard-4.0.1.tgz", + "integrity": "sha512-v/KBnfyaOMPmZc/dmc6ozOdWqekGp7bBGq4jLAecEfPGmfKiWS4sA8sC0LqiV9w5qmXAtXVn4M3p1jSyhY85SQ==", + "dev": true + }, "eslint-scope": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", @@ -5400,6 +5492,12 @@ "pkg-dir": "^3.0.0" } }, + "find-root": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz", + "integrity": "sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==", + "dev": true + }, "find-up": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", @@ -5656,6 +5754,12 @@ "resolved": "https://registry.npmjs.org/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.0.tgz", "integrity": "sha512-CIJYJC4GGF06TakLg8z4GQKvDsx9EMspVxOYih7LerEL/WosUnFIww45CGfxfeKHqlg3twgUrYRT1O3WQqjGCg==" }, + "get-stdin": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-7.0.0.tgz", + "integrity": "sha512-zRKcywvrXlXsA0v0i9Io4KDRaAw7+a1ZpjRwl9Wox8PFlVCCHra7E9c4kqXCoCM9nR5tBkaTTZRBoCm60bFqTQ==", + "dev": true + }, "get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", @@ -5791,9 +5895,9 @@ "integrity": "sha512-d4sze1JNC454Wdo2fkuyzCr6aHcbL6PGGuFAz0Li/NcOm1tCHGnWDRmJP85dh9IhQErTc2svWFEX5xHIOo//kQ==" }, "handlebars": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.2.0.tgz", - "integrity": "sha512-Kb4xn5Qh1cxAKvQnzNWZ512DhABzyFNmsaJf3OAkWNa4NkaqWcNI8Tao8Tasi0/F4JD9oyG0YxuFyvyR57d+Gw==", + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.3.tgz", + "integrity": "sha512-B0W4A2U1ww3q7VVthTKfh+epHx+q4mCt6iK+zEAzbMBpWQAwxCeKxEGpj/1oQTpzPXDNSOG7hmG14TsISH50yw==", "requires": { "neo-async": "^2.6.0", "optimist": "^0.6.1", @@ -9084,6 +9188,48 @@ "node-modules-regexp": "^1.0.0" } }, + "pkg-conf": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/pkg-conf/-/pkg-conf-3.1.0.tgz", + "integrity": "sha512-m0OTbR/5VPNPqO1ph6Fqbj7Hv6QU7gR/tQW40ZqrL1rjgCU85W6C1bJn0BItuJqnR98PWzw7Z8hHeChD1WrgdQ==", + "dev": true, + "requires": { + "find-up": "^3.0.0", + "load-json-file": "^5.2.0" + }, + "dependencies": { + "load-json-file": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-5.3.0.tgz", + "integrity": "sha512-cJGP40Jc/VXUsp8/OrnyKyTZ1y6v/dphm3bioS+RrKXjK2BB6wHUd6JptZEFDGgGahMT+InnZO5i1Ei9mpC8Bw==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.15", + "parse-json": "^4.0.0", + "pify": "^4.0.1", + "strip-bom": "^3.0.0", + "type-fest": "^0.3.0" + } + }, + "pify": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", + "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", + "dev": true + } + } + }, + "pkg-config": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pkg-config/-/pkg-config-1.1.1.tgz", + "integrity": "sha1-VX7yLXPaPIg3EHdmxS6tq94pj+Q=", + "dev": true, + "requires": { + "debug-log": "^1.0.0", + "find-root": "^1.0.0", + "xtend": "^4.0.1" + } + }, "pkg-dir": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", @@ -10864,6 +11010,12 @@ "is-promise": "^2.1.0" } }, + "run-parallel": { + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.9.tgz", + "integrity": "sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q==", + "dev": true + }, "run-queue": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/run-queue/-/run-queue-1.0.3.tgz", @@ -11554,6 +11706,35 @@ "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-1.0.2.tgz", "integrity": "sha512-MTX+MeG5U994cazkjd/9KNAapsHnibjMLnfXodlkXw76JEea0UiNzrqidzo1emMwk7w5Qhc9jd4Bn9TBb1MFwA==" }, + "standard": { + "version": "14.3.1", + "resolved": "https://registry.npmjs.org/standard/-/standard-14.3.1.tgz", + "integrity": "sha512-TUQwU7znlZLfgKH1Zwn/D84FitWZkUTfbxSiz/vFx+4c9GV+clSfG/qLiLZOlcdyzhw3oF5/pZydNjbNDfHPEw==", + "dev": true, + "requires": { + "eslint": "~6.4.0", + "eslint-config-standard": "14.1.0", + "eslint-config-standard-jsx": "8.1.0", + "eslint-plugin-import": "~2.18.0", + "eslint-plugin-node": "~10.0.0", + "eslint-plugin-promise": "~4.2.1", + "eslint-plugin-react": "~7.14.2", + "eslint-plugin-standard": "~4.0.0", + "standard-engine": "^12.0.0" + } + }, + "standard-engine": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/standard-engine/-/standard-engine-12.0.0.tgz", + "integrity": "sha512-gJIIRb0LpL7AHyGbN9+hJ4UJns37lxmNTnMGRLC8CFrzQ+oB/K60IQjKNgPBCB2VP60Ypm6f8DFXvhVWdBOO+g==", + "dev": true, + "requires": { + "deglob": "^4.0.0", + "get-stdin": "^7.0.0", + "minimist": "^1.1.0", + "pkg-conf": "^3.1.0" + } + }, "static-extend": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", @@ -12138,6 +12319,12 @@ "prelude-ls": "~1.1.2" } }, + "type-fest": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.3.1.tgz", + "integrity": "sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ==", + "dev": true + }, "type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", diff --git a/demoApp/package.json b/demoApp/package.json index c70fc26..a3e5f42 100644 --- a/demoApp/package.json +++ b/demoApp/package.json @@ -27,5 +27,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "devDependencies": { + "standard": "^14.3.1" } } diff --git a/demoApp/src/App.js b/demoApp/src/App.js index 330e366..1c32812 100644 --- a/demoApp/src/App.js +++ b/demoApp/src/App.js @@ -1,14 +1,13 @@ -import React from "react"; -import logo from "./logo.svg"; -import Demo from "./components/Demo"; -import "./App.css"; +import React from 'react' +import Demo from './components/Demo' +import './App.css' -function App() { +function App () { return ( -- Memory Address of created pointer: {this.state.ptr.value()}
*/} +- + Memory Address of created pointer: 0x10000{" "} + (obtained by ptr.value()) +
+ + {/*- Value stored in pointer is: {this.state.ptr.pointedTo()}
*/} +- + Value stored in pointer is: {this.state.ptr}{" "} + + Obtained by ptr.pointedTo() or ptr.point or + memoryJS.publicMemoryObj.valueOf(ptr.value())) + +
+ +- + +
+ +- + +
+ +- + +
++- ); + ) } -export default App; +export default App diff --git a/demoApp/src/App.test.js b/demoApp/src/App.test.js index a754b20..4bf1935 100644 --- a/demoApp/src/App.test.js +++ b/demoApp/src/App.test.js @@ -1,9 +1,9 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import App from './App'; +import React from 'react' +import ReactDOM from 'react-dom' +import App from './App' it('renders without crashing', () => { - const div = document.createElement('div'); - ReactDOM.render(, div); - ReactDOM.unmountComponentAtNode(div); -}); + const div = document.createElement('div') + ReactDOM.render( , div) + ReactDOM.unmountComponentAtNode(div) +}) diff --git a/demoApp/src/ReactMemory.js b/demoApp/src/ReactMemory.js index 74f3d1c..2174a3d 100644 --- a/demoApp/src/ReactMemory.js +++ b/demoApp/src/ReactMemory.js @@ -1,103 +1,103 @@ var memoryJS = { - name: "A memoryJS base global scoped object" -}; + name: 'A memoryJS base global scoped object' +} export class Pointer { - constructor(address = "0" /* address string */, local = false) { - var _value = address; - var _local = local; - this.isLocal = function() { - return _local; - }; - this.value = function() { - return _value; - }; + constructor (address = '0' /* address string */, local = false) { + var _value = address + var _local = local + this.isLocal = function () { + return _local + } + this.value = function () { + return _value + } } - pointedTo( + pointedTo ( MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */ ) { if (this.isLocal()) { - return MemoryObj.valueOf(this.value()); + return MemoryObj.valueOf(this.value()) } else { - return memoryJS.publicMemoryObj.valueOf(this.value()); + return memoryJS.publicMemoryObj.valueOf(this.value()) } } - changeValue( + changeValue ( object, MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */ ) { if (this.isLocal()) { - MemoryObj.changeValue(this.value(), object); + MemoryObj.changeValue(this.value(), object) } else { - memoryJS.publicMemoryObj.changeValue(this.value(), object); + memoryJS.publicMemoryObj.changeValue(this.value(), object) } - return 0; + return 0 } - free( + free ( MemoryObj /* in case of Local Memory object, pass it. Otherwise, leave it */ ) { if (this.isLocal()) { - MemoryObj.free(this.value()); + MemoryObj.free(this.value()) } else { - memoryJS.publicMemoryObj.free(); + memoryJS.publicMemoryObj.free() } - return null; + return null } - set point(object) { + set point (object) { if (this.isLocal()) { throw new Error( - "Pointer.point shorthand is only applicable for global pointers. Use changeValue() function instead" - ); + 'Pointer.point shorthand is only applicable for global pointers. Use changeValue() function instead' + ) } else { - this.changeValue(object); + this.changeValue(object) } } - get point() { + get point () { if (this.isLocal()) { throw new Error( - "Pointer.point shorthand is only applicable for global pointers. Use pointedTo() function instead" - ); + 'Pointer.point shorthand is only applicable for global pointers. Use pointedTo() function instead' + ) } else { - return this.pointedTo(); + return this.pointedTo() } } } export class Memory { - constructor(global = false) { - var _endaddr = 0; - var _objbook = []; - this.newobj = function(object /* object */) { - _objbook.push(object); - _endaddr = _endaddr + 1; + constructor (global = false) { + var _endaddr = 0 + var _objbook = [] + this.newobj = function (object /* object */) { + _objbook.push(object) + _endaddr = _endaddr + 1 if (global) { - return new Pointer((_endaddr - 1).toString(36)); + return new Pointer((_endaddr - 1).toString(36)) } else { - return new Pointer((_endaddr - 1).toString(36), true); + return new Pointer((_endaddr - 1).toString(36), true) } - }; + } - this.valueOf = function(address = "0" /* string */) { - return _objbook[parseInt(address, 36)]; - }; + this.valueOf = function (address = '0' /* string */) { + return _objbook[parseInt(address, 36)] + } - this.changeValue = function(address, object) { - _objbook[parseInt(address, 36)] = object; - return 0; - }; + this.changeValue = function (address, object) { + _objbook[parseInt(address, 36)] = object + return 0 + } - this.free = function(address = "0" /* string */) { - _objbook[parseInt(address, 36)] = null; - return 0; - }; + this.free = function (address = '0' /* string */) { + _objbook[parseInt(address, 36)] = null + return 0 + } - this.nullptr = this.newobj(null); + this.nullptr = this.newobj(null) } } -memoryJS.publicMemoryObj = new Memory(true); +memoryJS.publicMemoryObj = new Memory(true) diff --git a/demoApp/src/components/Demo.js b/demoApp/src/components/Demo.js index 6bce7f3..94a8dbd 100644 --- a/demoApp/src/components/Demo.js +++ b/demoApp/src/components/Demo.js @@ -1,85 +1,85 @@ -import * as memoryJS from "../ReactMemory.js"; -import React from "react"; +// import * as memoryJS from '../ReactMemory.js' +import React from 'react' export default class Demo extends React.Component { - constructor(props) { - super(props); + constructor (props) { + super(props) this.state = { - ptrInput: "", - ptr: "", + ptrInput: '', + ptr: '', ptrCreated: false, - customMemInput: "", - customMem: "" - }; + customMemInput: '', + customMem: '' + } - this.handlePtrCreate = this.handlePtrCreate.bind(this); - this.handleInputChange = this.handleInputChange.bind(this); - this.deletePtr = this.deletePtr.bind(this); - this.changeCustomMem = this.changeCustomMem.bind(this); + this.handlePtrCreate = this.handlePtrCreate.bind(this) + this.handleInputChange = this.handleInputChange.bind(this) + this.deletePtr = this.deletePtr.bind(this) + this.handleChangeCustomMem = this.handleChangeCustomMem.bind(this) } - handlePtrCreate(event) { - console.log("reached"); + handlePtrCreate (event) { + console.log('reached') // var pointer = memoryJS.Pointer.publicMemoryObj.newObj(255); - //Instead set ptr state var to be equal to a pointer to an object of value passed in. + // Instead set ptr state var to be equal to a pointer to an object of value passed in. - var pointer = this.state.ptrInput; - this.setState({ ptr: pointer, ptrCreated: true }); - event.preventDefault(); + var pointer = this.state.ptrInput + this.setState({ ptr: pointer, ptrCreated: true }) + event.preventDefault() } - handleInputChange(event) { - const target = event.target; - const value = target.value; - const name = target.name; + handleInputChange (event) { + const target = event.target + const value = target.value + const name = target.name this.setState({ [name]: value - }); + }) } - deletePtr(event) { - this.setState({ ptr: "", ptrCreated: true }); - event.preventDefault(); + deletePtr (event) { + this.setState({ ptr: '', ptrCreated: true }) + event.preventDefault() } - changeCustomMem(event) { + handleChangeCustomMem (event) { // create a new pointer at specific mem location - this.setState({ customMem: this.state.customMemInput }); - alert("New pointer was created pointing to " + this.state.customMem); - event.preventDefault(); + this.setState({ customMem: this.state.customMemInput }) + alert('New pointer was created pointing to ' + this.state.customMem) + event.preventDefault() } - render() { + render () { if (!this.state.ptrCreated) { return ( - ); + ) } else { return ({/*
- ); + ) } } } diff --git a/demoApp/src/index.js b/demoApp/src/index.js index 87d1be5..824d262 100644 --- a/demoApp/src/index.js +++ b/demoApp/src/index.js @@ -1,12 +1,12 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import './index.css'; -import App from './App'; -import * as serviceWorker from './serviceWorker'; +import React from 'react' +import ReactDOM from 'react-dom' +import './index.css' +import App from './App' +import * as serviceWorker from './serviceWorker' -ReactDOM.render(- Memory Address of created pointer: {this.state.ptr.value()}
*/}- - Memory Address of created pointer: 0x10000{" "} + Memory Address of created pointer: 0x10000{' '} (obtained by ptr.value())
{/*- Value stored in pointer is: {this.state.ptr.pointedTo()}
*/}- - Value stored in pointer is: {this.state.ptr}{" "} + Value stored in pointer is: {this.state.ptr}{' '} Obtained by ptr.pointedTo() or ptr.point or memoryJS.publicMemoryObj.valueOf(ptr.value())) @@ -97,32 +97,32 @@ export default class Demo extends React.Component { - +
- -
, document.getElementById('root')); +ReactDOM.render( , document.getElementById('root')) // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: https://bit.ly/CRA-PWA -serviceWorker.unregister(); +serviceWorker.unregister() diff --git a/demoApp/src/serviceWorker.js b/demoApp/src/serviceWorker.js index f8c7e50..b1b6820 100644 --- a/demoApp/src/serviceWorker.js +++ b/demoApp/src/serviceWorker.js @@ -18,25 +18,25 @@ const isLocalhost = Boolean( window.location.hostname.match( /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ ) -); +) -export function register(config) { +export function register (config) { if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { // The URL constructor is available in all browsers that support SW. - const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); + const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href) if (publicUrl.origin !== window.location.origin) { // Our service worker won't work if PUBLIC_URL is on a different origin // from what our page is served on. This might happen if a CDN is used to // serve assets; see https://github.com/facebook/create-react-app/issues/2374 - return; + return } window.addEventListener('load', () => { - const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; + const swUrl = `${process.env.PUBLIC_URL}/service-worker.js` if (isLocalhost) { // This is running on localhost. Let's check if a service worker still exists or not. - checkValidServiceWorker(swUrl, config); + checkValidServiceWorker(swUrl, config) // Add some additional logging to localhost, pointing developers to the // service worker/PWA documentation. @@ -44,24 +44,24 @@ export function register(config) { console.log( 'This web app is being served cache-first by a service ' + 'worker. To learn more, visit https://bit.ly/CRA-PWA' - ); - }); + ) + }) } else { // Is not localhost. Just register service worker - registerValidSW(swUrl, config); + registerValidSW(swUrl, config) } - }); + }) } } -function registerValidSW(swUrl, config) { +function registerValidSW (swUrl, config) { navigator.serviceWorker .register(swUrl) .then(registration => { registration.onupdatefound = () => { - const installingWorker = registration.installing; + const installingWorker = registration.installing if (installingWorker == null) { - return; + return } installingWorker.onstatechange = () => { if (installingWorker.state === 'installed') { @@ -72,38 +72,38 @@ function registerValidSW(swUrl, config) { console.log( 'New content is available and will be used when all ' + 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' - ); + ) // Execute callback if (config && config.onUpdate) { - config.onUpdate(registration); + config.onUpdate(registration) } } else { // At this point, everything has been precached. // It's the perfect time to display a // "Content is cached for offline use." message. - console.log('Content is cached for offline use.'); + console.log('Content is cached for offline use.') // Execute callback if (config && config.onSuccess) { - config.onSuccess(registration); + config.onSuccess(registration) } } } - }; - }; + } + } }) .catch(error => { - console.error('Error during service worker registration:', error); - }); + console.error('Error during service worker registration:', error) + }) } -function checkValidServiceWorker(swUrl, config) { +function checkValidServiceWorker (swUrl, config) { // Check if the service worker can be found. If it can't reload the page. fetch(swUrl) .then(response => { // Ensure service worker exists, and that we really are getting a JS file. - const contentType = response.headers.get('content-type'); + const contentType = response.headers.get('content-type') if ( response.status === 404 || (contentType != null && contentType.indexOf('javascript') === -1) @@ -111,25 +111,25 @@ function checkValidServiceWorker(swUrl, config) { // No service worker found. Probably a different app. Reload the page. navigator.serviceWorker.ready.then(registration => { registration.unregister().then(() => { - window.location.reload(); - }); - }); + window.location.reload() + }) + }) } else { // Service worker found. Proceed as normal. - registerValidSW(swUrl, config); + registerValidSW(swUrl, config) } }) .catch(() => { console.log( 'No internet connection found. App is running in offline mode.' - ); - }); + ) + }) } -export function unregister() { +export function unregister () { if ('serviceWorker' in navigator) { navigator.serviceWorker.ready.then(registration => { - registration.unregister(); - }); + registration.unregister() + }) } }