Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[差分確認用] #9

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use_frameworks!

def main_pods
pod 'Realm'
pod 'Dollar'
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'RCTImage',
'RCTNetwork',
'RCTText',
'RCTWebSocket',
# Add any other subspecs you want to use in your project

]
end

Expand Down
3 changes: 3 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PODS:
- Dollar (4.0.1)
- Nimble (3.0.0)
- Quick (0.8.0)
- React/Core (0.14.2)
Expand All @@ -16,6 +17,7 @@ PODS:
- Realm/Headers (0.96.2)

DEPENDENCIES:
- Dollar
- Nimble (= 3.0.0)
- Quick (~> 0.8.0)
- React/Core (from `../node_modules/react-native`)
Expand All @@ -31,6 +33,7 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native"

SPEC CHECKSUMS:
Dollar: a058e2659e0d3261307c12630dbc2fd8e32f80bf
Nimble: 4c353d43735b38b545cbb4cb91504588eb5de926
Quick: 563d0f6ec5f72e394645adb377708639b7dd38ab
React: e0dc1498eee8800999917f437a027223f49d731d
Expand Down
18 changes: 1 addition & 17 deletions ios/ReactNativeWithPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
785801631C0D651500B6E94D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7858014C1C0D651500B6E94D /* Assets.xcassets */; };
785801641C0D651500B6E94D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7858014D1C0D651500B6E94D /* LaunchScreen.storyboard */; };
785801651C0D651500B6E94D /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7858014F1C0D651500B6E94D /* Info.plist */; };
785801661C0D651500B6E94D /* Media.swift in Sources */ = {isa = PBXBuildFile; fileRef = 785801531C0D651500B6E94D /* Media.swift */; };
785801671C0D651500B6E94D /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = 785801541C0D651500B6E94D /* Router.swift */; };
785801681C0D651500B6E94D /* Server.swift in Sources */ = {isa = PBXBuildFile; fileRef = 785801551C0D651500B6E94D /* Server.swift */; };
785801691C0D651500B6E94D /* PseudoServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 785801561C0D651500B6E94D /* PseudoServer.swift */; };
7858016A1C0D651500B6E94D /* Route.swift in Sources */ = {isa = PBXBuildFile; fileRef = 785801571C0D651500B6E94D /* Route.swift */; };
7858016B1C0D651500B6E94D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7858015A1C0D651500B6E94D /* AppDelegate.swift */; };
7858016C1C0D651500B6E94D /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7858015B1C0D651500B6E94D /* Config.swift */; };
7858016F1C0D651500B6E94D /* MyProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 785801601C0D651500B6E94D /* MyProtocol.swift */; };
785801701C0D651500B6E94D /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 785801611C0D651500B6E94D /* Utils.swift */; };
785801711C0D651500B6E94D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 785801621C0D651500B6E94D /* ViewController.swift */; };
78E52DAE1BFD577400EDB819 /* ReactNativeWithPodsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E52DAD1BFD577400EDB819 /* ReactNativeWithPodsTests.swift */; };
78E52DB91BFD577400EDB819 /* ReactNativeWithPodsUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E52DB81BFD577400EDB819 /* ReactNativeWithPodsUITests.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -54,17 +50,13 @@
7858014C1C0D651500B6E94D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
7858014E1C0D651500B6E94D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
7858014F1C0D651500B6E94D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
785801531C0D651500B6E94D /* Media.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Media.swift; sourceTree = "<group>"; };
785801541C0D651500B6E94D /* Router.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
785801551C0D651500B6E94D /* Server.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Server.swift; sourceTree = "<group>"; };
785801561C0D651500B6E94D /* PseudoServer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PseudoServer.swift; sourceTree = "<group>"; };
785801571C0D651500B6E94D /* Route.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Route.swift; sourceTree = "<group>"; };
785801581C0D651500B6E94D /* ReactNativeWithPods-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ReactNativeWithPods-Bridging-Header.h"; sourceTree = "<group>"; };
7858015A1C0D651500B6E94D /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7858015B1C0D651500B6E94D /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
785801601C0D651500B6E94D /* MyProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyProtocol.swift; sourceTree = "<group>"; };
785801611C0D651500B6E94D /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
785801621C0D651500B6E94D /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
78E52D951BFD577400EDB819 /* ReactNativeWithPods.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ReactNativeWithPods.app; sourceTree = BUILT_PRODUCTS_DIR; };
78E52DA91BFD577400EDB819 /* ReactNativeWithPodsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ReactNativeWithPodsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
78E52DAD1BFD577400EDB819 /* ReactNativeWithPodsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactNativeWithPodsTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -108,11 +100,11 @@
7858014B1C0D651500B6E94D /* ReactNativeWithPods */ = {
isa = PBXGroup;
children = (
785801581C0D651500B6E94D /* ReactNativeWithPods-Bridging-Header.h */,
7858014C1C0D651500B6E94D /* Assets.xcassets */,
7858014D1C0D651500B6E94D /* LaunchScreen.storyboard */,
7858014F1C0D651500B6E94D /* Info.plist */,
785801501C0D651500B6E94D /* lib */,
785801581C0D651500B6E94D /* ReactNativeWithPods-Bridging-Header.h */,
785801591C0D651500B6E94D /* src */,
);
path = ReactNativeWithPods;
Expand All @@ -139,9 +131,6 @@
785801521C0D651500B6E94D /* lib */ = {
isa = PBXGroup;
children = (
785801531C0D651500B6E94D /* Media.swift */,
785801541C0D651500B6E94D /* Router.swift */,
785801551C0D651500B6E94D /* Server.swift */,
);
path = lib;
sourceTree = "<group>";
Expand All @@ -153,7 +142,6 @@
7858015B1C0D651500B6E94D /* Config.swift */,
785801601C0D651500B6E94D /* MyProtocol.swift */,
785801611C0D651500B6E94D /* Utils.swift */,
785801621C0D651500B6E94D /* ViewController.swift */,
);
path = src;
sourceTree = "<group>";
Expand Down Expand Up @@ -485,13 +473,9 @@
files = (
7858016B1C0D651500B6E94D /* AppDelegate.swift in Sources */,
785801691C0D651500B6E94D /* PseudoServer.swift in Sources */,
785801671C0D651500B6E94D /* Router.swift in Sources */,
7858016C1C0D651500B6E94D /* Config.swift in Sources */,
785801711C0D651500B6E94D /* ViewController.swift in Sources */,
785801681C0D651500B6E94D /* Server.swift in Sources */,
785801701C0D651500B6E94D /* Utils.swift in Sources */,
7858016A1C0D651500B6E94D /* Route.swift in Sources */,
785801661C0D651500B6E94D /* Media.swift in Sources */,
7858016F1C0D651500B6E94D /* MyProtocol.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
147 changes: 140 additions & 7 deletions ios/ReactNativeWithPods/lib/PseudoServer/PseudoServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,146 @@
//

import Foundation
import Dollar

class InternalWeb {
static let router = Router()
static let server = Server(router: router)
struct PseudoServer {

static func invoke(path: String) -> Response {
let req: Request = Request(["path": path])
return server.call(req)
/* -----------------------------------------------
* main
* ----------------------------------------------- */
static let ROUTE: RouteMap = [
"/foo": [Acts.session, Acts.auth],
"/bar": [Acts.session ]
]

static func query(path:String) -> Response {

let router = Router(routemap: ROUTE)
let server = Server(router: router)

return invoke(server, path: path)
}

private static func invoke(server: Server, path: String) -> Response {
let req: Request = ["path": path]
return server.call(req, res: Response() );
}


struct Acts {

static let session: Responsible = { req, res -> Response in
return res
}

static let auth: Responsible = { req, res -> Response in
return res
}
}

/* ----------------------------------------------- */

typealias RouteMap = [String : [Responsible]]

typealias Responsible = (Request,Response) -> Response

typealias Request = Dictionary<String,String>

/* ----------------------------------------------- */

class Response {

// TODO : wrap primitive response type
var header : [String]
var payload : [String]

convenience init() {
self.init(header: [""], payload: [""])
}

init(header: [String], payload: [String]) {
(self.header,self.payload) = (header,payload)
}

func header(header: String...) -> Response {
self.header += header
return self
}

func payload(payload: String...) -> Response {
self.payload += payload
return self
}

func end() -> Response {
p("end:", header.debugDescription, payload.debugDescription )
return self
}
}

/* ----------------------------------------------- */

class MiddleWare {

let stack: [ Responsible ]

init(funcs: [ Responsible ] ) { stack = funcs }

func handle(req: Request, res:Response) -> Response{
// MiddleWare.reduce()
return res.payload("うんこ")
}

static func reduce(stack: [Responsible], req: Request, res:Response) {
stack.count

// return Response()
}
}
/* ----------------------------------------------- */

class Router {
var route: [String: MiddleWare]

init(routemap: RouteMap) {
// TODO : FIXME
self.route.map([routemap.first]
routemap.forEach({ path, handlers in
self.register(path, handlers: handlers)
})
}

private func register(path: String, handlers: [Responsible]) {
if !self.route.keys.contains(path) {
self.route[path] = MiddleWare(funcs: handlers)
}
}

func handle(req: Request, res: Response)-> Response {
if let path = req["path"] {
if let middle = self.route[path] {
return middle.handle(req, res: res)
} else {
return res.payload("404 NOT FOUND")
}
} else {
return res.payload("BAD REQUEST")
}
}
}

/* ----------------------------------------------- */
class Server {

let router: Router

init(router: Router) {
self.router = router
}

func call(req: Request,res: Response) -> Response {
p("[Request]:", req.debugDescription)
return self.router.handle(req, res: res)
}
}
}
}
11 changes: 0 additions & 11 deletions ios/ReactNativeWithPods/lib/PseudoServer/Route.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,3 @@ enum http {
}


//protocol Routable: Dictionary<String,(http, RequestHandlable)> {
// let method: http
// let handler: RequestHandlable
//}
//
//protocol RequestHandlable {
// let _: Request -> Response
//}



27 changes: 0 additions & 27 deletions ios/ReactNativeWithPods/lib/PseudoServer/lib/Media.swift

This file was deleted.

28 changes: 0 additions & 28 deletions ios/ReactNativeWithPods/lib/PseudoServer/lib/Router.swift

This file was deleted.

2 changes: 1 addition & 1 deletion ios/ReactNativeWithPods/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
launchOptions: nil)
self.window = UIWindow.init(frame: UIScreen.mainScreen().bounds)

let myViewController = ViewController()
let myViewController = UIViewController()
myViewController.view = rootView

self.window!.rootViewController = myViewController
Expand Down
14 changes: 8 additions & 6 deletions ios/ReactNativeWithPods/src/MyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import UIKit

class MyProtocol: NSURLProtocol {

/* class methods */
override static func canInitWithRequest(request: NSURLRequest) -> Bool {

let host = Config().hostName

if let reqHost = request.URL?.host {
return isAcceptableHost(reqHost, defaultHost: host)
} else {
Expand All @@ -36,13 +37,14 @@ class MyProtocol: NSURLProtocol {
p("requestURL:",reqURL)

let path: String? = reqURL.path
let res: Response = InternalWeb.invoke(path!)

p(res.header) // for debug
p(res.body) // for debug

let data = res.body.dataUsingEncoding(NSUTF8StringEncoding)
// design PseudoServer ( NSURLRepuest ) -> NSHTTPURLResponse
let res: PseudoServer.Response = PseudoServer.query(path!)

p(res.header) // for debug
p(res.payload) // for debug
let data = res.payload.joinWithSeparator("").dataUsingEncoding(NSUTF8StringEncoding)
// TODO : migrate to my response.
let response = NSHTTPURLResponse(URL: reqURL,
statusCode: 200,
HTTPVersion: "1.1",
Expand Down
2 changes: 1 addition & 1 deletion ios/ReactNativeWithPods/src/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import Foundation

// for debugging.
func p<T>(objs:T...) -> [String] {
return objs.map({ print($0); return String($0) })
return objs.map({ print( String($0) ); return String($0) })
}
Loading