Skip to content

Commit

Permalink
Typescript port.
Browse files Browse the repository at this point in the history
  • Loading branch information
dicky authored and dicky committed May 24, 2020
1 parent d0a4c84 commit a7debeb
Show file tree
Hide file tree
Showing 9 changed files with 5,791 additions and 48 deletions.
5,679 changes: 5,679 additions & 0 deletions Demo/React/HelloWorld.WebPack/package-lock.json

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions Demo/React/HelloWorld.WebPack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@
]
},
"dependencies": {
"dotnetify": "^3.6.0",
"dotnetify": "file:dotnetify-4.0.0-DEV.tgz",
"react": "~16.11.0",
"react-dom": "~16.11.0"
},
"devDependencies": {
"@types/react": "~16.9.35",
"@types/react-dom": "~16.9.8",
"aspnet-webpack": "^3.0.0",
"babel-core": "~6.26.3",
"babel-loader": "~7.1.4",
"babel-preset-env": "~1.7.0",
"babel-preset-react": "~6.24.1",
"webpack": "^4.18.0",
"webpack-cli": "^3.1.0",
"webpack-dev-middleware": "^3.3.0",
"webpack-hot-middleware": "^2.23.1"
"ts-loader": "~7.0.4",
"typescript": "~3.9.3",
"webpack": "~4.18.0",
"webpack-cli": "~3.3.11",
"webpack-dev-middleware": "~3.3.0",
"webpack-hot-middleware": "~2.23.1"
}
}
17 changes: 17 additions & 0 deletions Demo/React/HelloWorld.WebPack/src/HelloWorld-withHook.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import { useConnect } from 'dotnetify';

interface State {
Greetings: string;
ServerTime: string;
}

export const HelloWorld = () => {
const { state } = useConnect<State>('HelloWorld', this);
return (
<div>
<p>{state.Greetings}</p>
<p>Server time is: {state.ServerTime}</p>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from 'react';
import * as React from 'react';
import dotnetify from 'dotnetify';

export default class HelloWorld extends React.Component {
constructor(props) {
super(props);
this.state = { Greetings: '', ServerTime: '' };
interface State {
Greetings: string;
ServerTime: string;
}

export class HelloWorld extends React.Component<any, State> {
state: State = { Greetings: '', ServerTime: '' };

constructor(props: any) {
super(props);
dotnetify.react.connect('HelloWorld', this);
}

Expand Down
5 changes: 0 additions & 5 deletions Demo/React/HelloWorld.WebPack/src/index.js

This file was deleted.

5 changes: 5 additions & 0 deletions Demo/React/HelloWorld.WebPack/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { HelloWorld } from './HelloWorld-withHook';

ReactDOM.render(<HelloWorld />, document.getElementById('App'));
17 changes: 17 additions & 0 deletions Demo/React/HelloWorld.WebPack/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"jsx": "react",
"allowJs": true,
"declaration": true,
"declarationDir": "./typings",
"lib": ["dom", "es7"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
14 changes: 9 additions & 5 deletions Demo/React/HelloWorld.WebPack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

module.exports = {
mode: 'development',
entry: { main: './src/index.js' },
entry: { main: './src/index' },
output: {
path: __dirname + '/wwwroot/dist',
publicPath: '/dist/'
publicPath: '/dist/',
},
resolve: {
modules: [ 'src', 'node_modules' ]
extensions: ['.tsx', '.ts', '.js'],
modules: ['src', 'node_modules'],
},
module: {
rules: [ { test: /\.jsx?$/, use: 'babel-loader', exclude: /node_modules/ } ]
}
rules: [
{ test: /\.jsx?$/, use: 'babel-loader', exclude: /node_modules/ },
{ test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ },
],
},
};
73 changes: 45 additions & 28 deletions Demo/React/HelloWorld.WebPack/wwwroot/dist/main.js

Large diffs are not rendered by default.

0 comments on commit a7debeb

Please sign in to comment.