Skip to content

Commit

Permalink
first pass at typescript and seamless immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
toranb committed May 18, 2017
1 parent 1716f72 commit 0fe9bfa
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 23 deletions.
2 changes: 0 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import config from './config/environment';

let App;

Ember.MODEL_FACTORY_INJECTIONS = true;

App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Expand Down
15 changes: 15 additions & 0 deletions app/config/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default config;

/**
* Type declarations for
* import config from './config/environment'
*
* For now these need to be managed by the developer
* since different ember addons can materialize new entries.
*/
declare namespace config {
export var environment: any;
export var modulePrefix: string;
export var podModulePrefix: string;
export var locationType: string;
}
20 changes: 0 additions & 20 deletions app/reducers/users.js

This file was deleted.

36 changes: 36 additions & 0 deletions app/reducers/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import _ from 'lodash';
import * as SI from 'seamless-immutable';

const Immutable = SI['default'] ? SI['default'] : SI;

const initialState = Immutable({
all: undefined,
authenticatedId: undefined
});

interface User {
id: number;
name: string;
}

interface Action {
type: string;
user: User;
}

interface UserState {
all: Array<User>;
authenticatedId: number;
}

export default ((state: SI.ImmutableObject<UserState>, action: Action): SI.ImmutableObject<UserState> => {
switch(action.type) {
case 'ASSIGN_USER': {
const user = {[action.user.id]: action.user};
return state.merge({all: user, authenticatedId: action.user.id});
}
default: {
return state || initialState;
}
}
});
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"test": "ember test"
},
"devDependencies": {
"@types/ember": "^2.7.34",

This comment has been minimized.

Copy link
@danielchappell

danielchappell May 18, 2017

um since when?

This comment has been minimized.

Copy link
@toranb

toranb May 18, 2017

Author Owner

I wanna say May 5th it got rolling again - see this 2 part blog series from the new maintainer

http://www.chriskrycho.com/2017/typing-your-ember-part-1.html
http://www.chriskrycho.com/2017/typing-your-ember-part-2.html

"@types/lodash": "^4.14.64",
"@types/seamless-immutable": "^6.1.2",
"broccoli-asset-rev": "^2.4.5",
"ember-cli": "2.13.1",
"ember-cli-app-version": "^3.0.0",
Expand All @@ -30,6 +33,7 @@
"ember-cli-sass": "^6.1.2",
"ember-cli-shims": "^1.1.0",
"ember-cli-sri": "^2.1.0",
"ember-cli-typescript": "^0.4.0",
"ember-cli-uglify": "^1.2.0",
"ember-component-css": "^0.3.3",
"ember-export-application-global": "^2.0.0",
Expand All @@ -49,7 +53,8 @@
"normalizr": "^3.2.2",
"redux": "^3.6.0",
"redux-thunk": "^2.2.0",
"reselect": "^2.5.4"
"reselect": "^2.5.4",
"typescript": "^2.1"
},
"engines": {
"node": ">= 4"
Expand Down
22 changes: 22 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"allowJs": true,
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,

This comment has been minimized.

Copy link
@danielchappell

danielchappell May 18, 2017

should add the flag that turns off nullable types..

This comment has been minimized.

Copy link
@toranb

toranb May 18, 2017

Author Owner

what is the name of that one? I'll add it -see if this train wreck still works afterwards

"noEmitOnError": false,
"noEmit": true,
"baseUrl": ".",
"paths": {
"welp/tests/*": ["tests/*"],
"welp/*": ["app/*"]
}
},
"include": [
"app/**/*",
"tests/**/*"
]
}

0 comments on commit 0fe9bfa

Please sign in to comment.