This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as AWS from 'aws-sdk' | |
import 'source-map-support/register' | |
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda' | |
import * as uuid from 'uuid' | |
import { TodoItem } from '../../models/TodoItem' | |
export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => { | |
const data = JSON.parse(event.body); | |
const id = uuid.v4(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface TodoItem { | |
id: string | |
name: string | |
done: boolean | |
createdAt: string | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: | |
name: todo-api | |
custom: | |
webpack: | |
webpackConfig: ./webpack.config.js | |
includeModules: true | |
plugins: | |
- serverless-webpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: | |
name: todo-api | |
# app and org for use with dashboard.serverless.com | |
#app: your-app-name | |
#org: your-org-name | |
custom: | |
webpack: | |
webpackConfig: ./webpack.config.js | |
includeModules: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Without DI | |
class Store { | |
static let shared = Store() | |
func save(key, String, value: Any) { /*...*/ } | |
func load(key: String) -> Any? { /*...*/ } | |
} | |
class ViewModel { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@propertyWrapper | |
public struct Injected<Value> { | |
public var wrappedValue: Value { | |
get { | |
SwiftDI.default.resolve() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func registerDependencies() { | |
SwiftDI.configure { | |
$0.factory { Repository() } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository {} | |
class ViewModel { | |
@Injected var repository: Repository | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@propertyWrapper | |
public struct Injected<Value> { | |
private var value: Value? | |
public var wrappedValue: Value { | |
get { | |
return value ?? SwiftDI.default.resolve() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal enum Resolver { | |
case single(object: Any) | |
case factory(block: () -> Any) | |
func resolve() -> Any { | |
switch self { | |
case .single(let object): return object | |
case .factory(let block): return block() | |
} | |
} |