Skip to content

Commit 59ea18d

Browse files
committed
Removing pattern import * as RdfLib from 'rdflib'
1 parent 956f439 commit 59ea18d

10 files changed

Lines changed: 43 additions & 51 deletions

File tree

src/chat/infinite.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
* @packageDocumentation
44
*/
55

6-
/* global alert $rdf */
7-
import DateFolder from './dateFolder'
6+
/* global alert */
7+
const $rdf = require('rdflib')
8+
const DateFolder = require('./dateFolder')
89

910
// @@ trace20190428T1745
1011

@@ -140,6 +141,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
140141
return true
141142
}
142143
*/
144+
143145
/* Form for a new message
144146
*/
145147
function newMessageForm (messageTable) {
@@ -203,14 +205,15 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
203205
field.select()
204206
}
205207
}
208+
206209
if (
207210
SERVER_MKDIRP_BUG &&
208211
(kb.fetcher.requested[chatDocument.uri] === undefined ||
209212
kb.fetcher.requested[chatDocument.uri] === 404)
210213
) {
211214
console.log(
212215
'@@@ SERVER_MKDIRP_BUG: Should only happen once: create chat file: ' +
213-
chatDocument
216+
chatDocument
214217
)
215218
await createIfNotExists(chatDocument)
216219
}
@@ -305,17 +308,20 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
305308

306309
const chatDocument = dateFolder.leafDocumentFromDate(new Date())
307310
var imageDoc
311+
308312
function getImageDoc () {
309313
imageDoc = kb.sym(
310314
chatDocument.dir().uri + 'Image_' + Date.now() + '.png'
311315
)
312316
return imageDoc
313317
}
318+
314319
async function tookPicture (imageDoc) {
315320
if (imageDoc) {
316321
await sendMessage(imageDoc.uri)
317322
}
318323
}
324+
319325
middle.appendChild(
320326
UI.media.cameraButton(dom, kb, getImageDoc, tookPicture)
321327
)
@@ -366,7 +372,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
366372
})
367373

368374
// eslint-disable-next-line space-in-parens
369-
for (ele = messageTable.firstChild; ele; ) {
375+
for (ele = messageTable.firstChild; ele;) {
370376
ele2 = ele.nextSibling
371377
if (ele.AJAR_subject && !stored[ele.AJAR_subject.uri]) {
372378
messageTable.removeChild(ele)
@@ -432,6 +438,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
432438
}
433439
return live // not done
434440
}
441+
435442
/* Remove message tables earlier than this one
436443
*/
437444
function removePreviousMessages (backwards, messageTable) {
@@ -495,6 +502,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
495502
setScrollBackButtonIcon()
496503
return done
497504
}
505+
498506
function setScrollBackButtonIcon () {
499507
const sense = messageTable.extendedBack ? !newestFirst : newestFirst
500508
const scrollBackIcon = messageTable.initial
@@ -509,6 +517,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
509517
return sense ? 'noun_1369241.svg' : 'noun_1369237.svg'
510518
}
511519
}
520+
512521
async function scrollBackButtonHandler (_event) {
513522
if (messageTable.extendedBack) {
514523
removePreviousMessages(true, messageTable)
@@ -536,6 +545,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
536545
setScrollForwardButtonIcon()
537546
return done
538547
}
548+
539549
function setScrollForwardButtonIcon () {
540550
const sense = messageTable.extendedForwards ? !newestFirst : newestFirst // noun_T-Block_1114657_000000.svg
541551
const scrollForwardIcon = messageTable.final
@@ -550,6 +560,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
550560
return !sense ? 'noun_1369241.svg' : 'noun_1369237.svg'
551561
}
552562
}
563+
553564
async function scrollForwardButtonHandler (_event) {
554565
if (messageTable.extendedForwards) {
555566
removePreviousMessages(false, messageTable)
@@ -702,6 +713,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
702713
}
703714
}
704715
}
716+
705717
/*
706718
function messageCount () {
707719
var n = 0
@@ -713,6 +725,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
713725
return n
714726
}
715727
*/
728+
716729
/* Add the live message block with entry field for today
717730
*/
718731
async function appendCurrentMessages () {
@@ -754,6 +767,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
754767
var latest = { messageTable: null }
755768

756769
var lock = false
770+
757771
async function loadMoreWhereNeeded (event, fixScroll) {
758772
if (lock) return
759773
lock = true
@@ -788,7 +802,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
788802
const scrollTop = div.scrollTop
789803
console.log(
790804
'infinite scroll: adding below: bottom: ' +
791-
(div.scrollHeight - div.scrollTop - div.clientHeight)
805+
(div.scrollHeight - div.scrollTop - div.clientHeight)
792806
)
793807
done = await latest.messageTable.extendForwards() // then add more data on the bottom
794808
if (freeze) {
@@ -842,6 +856,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
842856
document.body.addEventListener('scroll', loadMoreWhereNeeded)
843857
}
844858
}
859+
845860
go()
846861
return div
847862
}

src/chat/thread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @packageDocumentation
44
*/
55

6-
/* global $rdf */
76
var UI = {
87
authn: require('../authn/authn'),
98
icons: require('../iconBase'),
@@ -17,6 +16,7 @@ var UI = {
1716
}
1817

1918
const utils = require('../utils')
19+
const $rdf = require('rdflib')
2020

2121
// var buttonStyle = 'font-size: 100%; margin: 0.8em; padding:0.5em; background-color: white;'
2222

src/messageArea.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global $rdf */
21
// Common code for a discussion are a of messages about something
32
//
43
var UI = {
@@ -13,6 +12,7 @@ var UI = {
1312
widgets: require('./widgets')
1413
}
1514

15+
const $rdf = require('rdflib')
1616
const utils = require('./utils')
1717

1818
// var buttonStyle = 'font-size: 100%; margin: 0.8em; padding:0.5em; background-color: white;'

test/unit/chat/bookmarks.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as RdfLib from 'rdflib'
21
import { findBookmarkDocument, toggleBookmark, renderBookmarksButton } from '../../../src/chat/bookmarks'
2+
import { NamedNode } from 'rdflib'
33

44
jest.mock('solid-auth-client')
55

@@ -33,8 +33,8 @@ describe('toggleBookmark', () => {
3333
})
3434
it('runs', async () => {
3535
const userContext = {
36-
me: new RdfLib.NamedNode('http://example.com'),
37-
bookmarkDocument: new RdfLib.NamedNode('http://example.com')
36+
me: new NamedNode('http://example.com'),
37+
bookmarkDocument: new NamedNode('http://example.com')
3838
}
3939
const target = {}
4040
const bookmarkButton = {}
@@ -52,8 +52,8 @@ describe('renderBookmarksButton', () => {
5252
})
5353
it('runs', async () => {
5454
const userContext = {
55-
me: new RdfLib.NamedNode('http://example.com'),
56-
bookmarkDocument: new RdfLib.NamedNode('http://example.com')
55+
me: new NamedNode('http://example.com'),
56+
bookmarkDocument: new NamedNode('http://example.com')
5757
}
5858
const target = {}
5959
const result = await renderBookmarksButton(userContext, target)

test/unit/chat/infinite.test.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import * as RdfLib from 'rdflib'
21
import { JSDOM } from 'jsdom'
3-
42
import { infiniteMessageArea } from '../../../src/chat/infinite'
3+
import { graph, sym } from 'rdflib'
54

65
jest.mock('solid-auth-client')
76
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window.document
@@ -11,27 +10,9 @@ describe('infiniteMessageArea', () => {
1110
expect(infiniteMessageArea).toBeInstanceOf(Function)
1211
})
1312
it('runs', () => {
14-
const kb = RdfLib.graph()
15-
const chatChannel = {
16-
dir () {
17-
return {
18-
uri: ''
19-
}
20-
}
21-
}
13+
const kb = graph()
14+
const chatChannel = sym('https://domain.tld/chat')
2215
const options = {}
23-
;(window as any).$rdf = {
24-
Namespace: () => {
25-
return () => ''
26-
},
27-
Query: function () {
28-
this.vars = []
29-
this.pat = {
30-
add: () => {}
31-
}
32-
},
33-
variable: () => {}
34-
}
3516
;(window as any).alert = () => {}
3617

3718
const result = infiniteMessageArea(dom, kb, chatChannel, options)

test/unit/chat/thread.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as RdfLib from 'rdflib'
21
import { JSDOM } from 'jsdom'
32
import thread from '../../../src/chat/thread'
3+
import { graph, sym } from 'rdflib'
44

55
jest.mock('solid-auth-client')
66
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window.document
@@ -11,12 +11,11 @@ describe('Thread', () => {
1111
})
1212

1313
it.skip('runs', () => {
14-
const kb = RdfLib.graph()
14+
const kb = graph()
1515
const subject = ''
16-
const messageStore = RdfLib.sym('https://test.test#')
16+
const messageStore = sym('https://test.test#')
1717
const options = {}
1818

19-
;(window as any).$rdf = RdfLib
2019
;(window as any).alert = () => {}
2120
expect(thread(dom, kb, subject, messageStore, options)).toBeInstanceOf(Object)
2221
})

test/unit/folders.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { JSDOM } from 'jsdom'
22
import { deleteRecursive, deleteFolder } from '../../src/folders'
3-
import * as RdfLib from 'rdflib'
3+
import { graph } from 'rdflib'
44

55
jest.mock('solid-auth-client')
66
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window.document
@@ -10,8 +10,6 @@ describe('deleteRecursive', () => {
1010
expect(deleteRecursive).toBeInstanceOf(Function)
1111
})
1212
it.skip('runs', async () => {
13-
;(window as any).$rdf = RdfLib
14-
;(window as any).$rdf.fetcher = new RdfLib.Fetcher((window as any).$rdf, {})
1513
expect(await deleteRecursive()).toEqual(undefined)
1614
})
1715
})
@@ -21,6 +19,6 @@ describe('deleteFolder', () => {
2119
expect(deleteFolder).toBeInstanceOf(Function)
2220
})
2321
it('runs', () => {
24-
expect(deleteFolder({}, RdfLib.graph(), dom)).toBeTruthy()
22+
expect(deleteFolder({}, graph(), dom)).toBeTruthy()
2523
})
2624
})

test/unit/messageArea.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { JSDOM } from 'jsdom'
22
import MessageArea from '../../src/messageArea'
3-
import * as RdfLib from 'rdflib'
3+
import { graph, sym } from 'rdflib'
44

55
jest.mock('solid-auth-client')
66
const window = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window
@@ -11,12 +11,11 @@ describe('MessageArea', () => {
1111
expect(MessageArea).toBeInstanceOf(Function)
1212
})
1313
it('runs', () => {
14-
;(global as any).$rdf = RdfLib
1514
expect(MessageArea(
1615
dom,
17-
RdfLib.graph(),
18-
RdfLib.sym('https://test.test'),
19-
RdfLib.sym('https://test.test'),
16+
graph(),
17+
sym('https://test.test'),
18+
sym('https://test.test'),
2019
{}
2120
)).toBeTruthy()
2221
})

test/unit/preferences.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { JSDOM } from 'jsdom'
2-
import * as RdfLib from 'rdflib'
32
import Preferences from '../../src/preferences'
3+
import { sym } from 'rdflib'
44

55
jest.mock('solid-auth-client')
66
const window = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window
@@ -41,7 +41,7 @@ describe('Preferences.renderPreferencesForm', () => {
4141
expect(Preferences.renderPreferencesForm).toBeInstanceOf(Function)
4242
})
4343
it('runs', () => {
44-
const subject = RdfLib.sym('https://test.test')
44+
const subject = sym('https://test.test')
4545
const klass = {}
4646
const preferencesForm = {}
4747
const context = { dom }

test/unit/widgets/dragAndDrop.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as RdfLib from 'rdflib'
21
import { JSDOM } from 'jsdom'
32

43
import {
54
makeDropTarget,
65
makeDraggable,
76
uploadFiles
87
} from '../../../src/widgets/dragAndDrop'
8+
import { fetcher } from 'rdflib'
99

1010
jest.mock('solid-auth-client')
1111
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window.document
@@ -59,7 +59,7 @@ describe('uploadFiles', () => {
5959
const imageBase = ''
6060
const successHandler = () => {}
6161
expect(
62-
uploadFiles(RdfLib.fetcher, files, fileBase, imageBase, successHandler)
62+
uploadFiles(fetcher, files, fileBase, imageBase, successHandler)
6363
).toEqual(undefined)
6464
})
6565
})

0 commit comments

Comments
 (0)