Upgrade to Pro — share decks privately, control downloads, hide ads and more …

入力を型で表現する

Motoki Narita
October 25, 2017

 入力を型で表現する

Motoki Narita

October 25, 2017
Tweet

More Decks by Motoki Narita

Other Decks in Technology

Transcript

  1. struct ProactiveExhibit { enum Input: Equatable { case ean(String) case

    exhibit(BulkIncludeExhibit) } let input: Input } ೖྗͷந৅Խ
  2. struct ProactiveExhibit { enum Input: Equatable { case ean(String) case

    exhibit(BulkIncludeExhibit) } let input: Input } Χϝϥ͔ΒऔಘͰ͖Δ&"/ίʔυ
 ʢ੡඼৘ใऔಘΛ"1*ܦ༝Ͱऔಘʣ
  3. struct ProactiveExhibit { enum Input: Equatable { case ean(String) case

    exhibit(BulkIncludeExhibit) } let input: Input } λΠτϧݕࡧը໘͔Β౉͞ΕΔ੡඼৘ใ
 ʢݕࡧࡁΈͷ੡඼৘ใ͕ͦͷ··౉͞ΕΔʣ
  4. let input = Observable .of(scanCamera.barcodeNumber.map { ProactiveExhibit.Input.ean($0) }, exhibitAdapter.map {

    ProactiveExhibit.Input.exhibit(BulkIncludeExhibit(exhibits: [$0])) } ) .merge() .asDriver(onErrorDriveWith: .empty()) let removeExhibitsInput = Observable .merge(GlobalObservable.removeExhibitsForExhibitCamera, removeExhibitAdapter) .asDriver(onErrorDriveWith: .empty()) let replaceExhibitInput = replaceExhibitAdapter.asDriver(onErrorDriveWith: .empty()) viewModel = ExhibitCameraViewModel(input: input, removeExhibitsInput: removeExhibitsInput, replaceExhibitInput: replaceExhibitInput) Χϝϥ͔Β౉ͬͯ͘Δ&"/ίʔυͷετϦʔϜͱɺ
 λΠτϧը໘͔Β౉͞ΕΔ੡඼σʔλͷετϦʔϜΛNFSHF
 ˠ%SJWFS1SPBDUJWF&YIJCJU*OQVU
  5. let input = Observable .of(scanCamera.barcodeNumber.map { ProactiveExhibit.Input.ean($0) }, exhibitAdapter.map {

    ProactiveExhibit.Input.exhibit(BulkIncludeExhibit(exhibits: [$0])) } ) .merge() .asDriver(onErrorDriveWith: .empty()) let removeExhibitsInput = Observable .merge(GlobalObservable.removeExhibitsForExhibitCamera, removeExhibitAdapter) .asDriver(onErrorDriveWith: .empty()) let replaceExhibitInput = replaceExhibitAdapter.asDriver(onErrorDriveWith: .empty()) viewModel = ExhibitCameraViewModel(input: input, removeExhibitsInput: removeExhibitsInput, replaceExhibitInput: replaceExhibitInput) Χϝϥ͔Β౉ͬͯ͘Δ&"/ίʔυͷετϦʔϜ
  6. let input = Observable .of(scanCamera.barcodeNumber.map { ProactiveExhibit.Input.ean($0) }, exhibitAdapter.map {

    ProactiveExhibit.Input.exhibit(BulkIncludeExhibit(exhibits: [$0])) } ) .merge() .asDriver(onErrorDriveWith: .empty()) let removeExhibitsInput = Observable .merge(GlobalObservable.removeExhibitsForExhibitCamera, removeExhibitAdapter) .asDriver(onErrorDriveWith: .empty()) let replaceExhibitInput = replaceExhibitAdapter.asDriver(onErrorDriveWith: .empty()) viewModel = ExhibitCameraViewModel(input: input, removeExhibitsInput: removeExhibitsInput, replaceExhibitInput: replaceExhibitInput) λΠτϧը໘͔Β౉͞ΕΔ੡඼σʔλͷετϦʔϜ
  7. let input = Observable .of(scanCamera.barcodeNumber.map { ProactiveExhibit.Input.ean($0) }, exhibitAdapter.map {

    ProactiveExhibit.Input.exhibit(BulkIncludeExhibit(exhibits: [$0])) } ) .merge() .asDriver(onErrorDriveWith: .empty()) let removeExhibitsInput = Observable .merge(GlobalObservable.removeExhibitsForExhibitCamera, removeExhibitAdapter) .asDriver(onErrorDriveWith: .empty()) let replaceExhibitInput = replaceExhibitAdapter.asDriver(onErrorDriveWith: .empty()) viewModel = ExhibitCameraViewModel(input: input, removeExhibitsInput: removeExhibitsInput, replaceExhibitInput: replaceExhibitInput) ೖྗΛ7JFX.PEFMͷॳظԽ࣌ʹ౉͢
  8. let fetchProgress = filteredInput .flatMap { [weak self] input ->

    Driver<Progress<(ProactiveExhibit.Input, [Exhibit])>> in switch input { case .ean(let ean): let request = ExhibitAPI.FindByEAN(ean: ean) let response = APIClient.shared.response(request) .map { response -> (ProactiveExhibit.Input, [Exhibit]) in return (input, response.elements) } return Progress.makeDriver(response) case .exhibit(let exhibit): return Driver.empty() } } *OQVUFBOͷ৔߹ͷΈϦΫΤετ
  9. class ExhibitScannedDisplayViewCell: UICollectionViewCell { // লུ var proactiveExhibit: ProactiveExhibit? {

    didSet { if let bulkIncludeExhibit = proactiveExhibit?.bulkIncludeExhibit { // ੡඼৘ใදࣔ } else { // ϓϨʔεϗϧμදࣔ } } } } "1*ϦΫΤετ͕ඞཁͳ৔߹ʢFBOʣ͸
 ϓϨʔεϗϧμΛදࣔ͢ΔΑ͏$FMMͰදࣔॲཧ
  10. class ExhibitScannedDisplayViewCell: UICollectionViewCell { // লུ var proactiveExhibit: ProactiveExhibit? {

    didSet { if let bulkIncludeExhibit = proactiveExhibit?.bulkIncludeExhibit { // ੡඼৘ใදࣔ } else { // ϓϨʔεϗϧμදࣔ } } } } ೖྗʹܕΛఆٛ͢Δ͜ͱͰσʔλͦͷ΋ͷͱ͸
 ผͰॲཧ͕Ͱ͖ΔΑ͏ʹͳΔ