Skip to content

Commit

Permalink
feat: initialize typescript (#60)
Browse files Browse the repository at this point in the history
* feat: initialize typescript

* chore: keep babel

* chore: remove sourcemaps, @types/url-parse
  • Loading branch information
johncardiologs authored Jun 11, 2024
1 parent aaba7da commit 3677d94
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 26 deletions.
5 changes: 4 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion superglue/.babelrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
plugins: [
["transform-react-remove-prop-types", {removeImport: true}]
["transform-react-remove-prop-types", { removeImport: true }]
],
presets: [
[
Expand All @@ -14,5 +14,8 @@ module.exports = {
[
"@babel/preset-react"
],
[
"@babel/preset-typescript"
],
],
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import React from 'react'
import { urlToPageKey, pathWithoutBZParams } from '../utils'
import { REMOVE_PAGE, HISTORY_CHANGE } from '../actions'
import PropTypes from 'prop-types'

class Nav extends React.Component {
interface Props {
store: any
history: any
mapping: any
visit: any
remote: any
initialPageKey: any
}

interface State {
pageKey: any
ownProps: any
}

class Nav extends React.Component<Props, State> {
public history
public hasWindow
public unsubscribeHistory

constructor(props) {
super(props)
const { history, initialPageKey } = this.props
Expand Down Expand Up @@ -211,13 +228,4 @@ class Nav extends React.Component {
}
}

Nav.propTypes = {
store: PropTypes.object,
history: PropTypes.object,
mapping: PropTypes.object,
visit: PropTypes.func,
remote: PropTypes.func,
initialPageKey: PropTypes.string,
}

export default Nav
File renamed without changes.
29 changes: 19 additions & 10 deletions superglue/lib/index.js → superglue/lib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import thunk from 'redux-thunk'
import { Provider, connect } from 'react-redux'
import { createBrowserHistory, createMemoryHistory } from 'history'
import Nav from './components/Nav'
import PropTypes from 'prop-types'

export {
BEFORE_FETCH,
Expand All @@ -40,7 +39,6 @@ export {
superglueReducer,
pageReducer,
rootReducer,
updateFragments,
} from './reducers'
export { fragmentMiddleware } from './middleware'
export { getIn } from './utils/immutability'
Expand Down Expand Up @@ -94,7 +92,25 @@ class NotImplementedError extends Error {
}
}

export class ApplicationBase extends React.Component {
interface Props {
initialPage: any
baseUrl: any
path: any
}

interface Store {}

export class ApplicationBase extends React.Component<Props, Store> {
public hasWindow: any
public navigatorRef: any
public initialPageKey: any
public store: any
public history: any
public connectedMapping: any
public ujsHandlers: any
public visit: any
public remote: any

constructor(props) {
super(props)
this.hasWindow = typeof window !== 'undefined'
Expand Down Expand Up @@ -220,10 +236,3 @@ export class ApplicationBase extends React.Component {
)
}
}

ApplicationBase.propTypes = {
initialPage: PropTypes.object,
baseUrl: PropTypes.string,
path: PropTypes.string,
appEl: PropTypes.object,
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion superglue/lib/utils/ujs.js → superglue/lib/utils/ujs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { withoutBusters, urlToPageKey } from './url'

export class HandlerBuilder {
public attributePrefix: any
public visit: any
public remote: any

constructor({ ujsAttributePrefix, visit, remote }) {
this.attributePrefix = ujsAttributePrefix
this.isUJS = this.isUJS.bind(this)
Expand Down Expand Up @@ -84,7 +88,7 @@ export class HandlerBuilder {
this.visitOrRemote(link, url, { method: 'GET' })
}

visitOrRemote(linkOrForm, url, opts = {}) {
visitOrRemote(linkOrForm, url, opts: any = {}) {
let target

if (linkOrForm.getAttribute(this.attributePrefix + '-visit')) {
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions superglue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"clean": "rm -rf ./dist",
"copy:package": "cat ./package.json | jq 'del(.scripts)' > dist/package.json",
"copy:readme": "cp ../README.md dist/",
"build:index": "babel lib -d dist",
"build": "npm run clean && npm run build:index && npm run copy:package && npm run copy:readme",
"build": "npm run clean && npm run build:js && npm run copy:package && npm run copy:readme",
"build:js": "babel lib --out-dir dist --extensions \".ts,.tsx\"",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"prepublishOnly": "npm run build"
},
"repository": {
Expand All @@ -27,6 +29,7 @@
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.4",
"@babel/preset-react": "^7.13.13",
"@babel/preset-typescript": "^7.24.6",
"core-js": "^2.6.12",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
Expand Down
12 changes: 12 additions & 0 deletions superglue/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"jsx": "react",
"allowJs": true,
"target": "es5",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"include": [
"./lib/**/*"
]
}

0 comments on commit 3677d94

Please sign in to comment.