Giter Site home page Giter Site logo

retrolux's People

Contributors

bhendersonizeni avatar cbh2000 avatar mitch10e avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

retrolux's Issues

Swift 4

This library won't compile on Swift 4 with multiple errors.

Option NSNumber To Int Tranformer doesn't work

Have the following transformer which doesn't work:

class OptionalNSNumberToIntTranformer: NestedTransformer {
    typealias TypeOfData = NSNumber?
    typealias TypeOfProperty = Int
    
    func setter(_ dataValue: NSNumber?, type: Any.Type) throws -> Int {
        return dataValue?.intValue ?? 0
    }
    
    func getter(_ propertyValue: Int) throws -> NSNumber? {
        return NSNumber(integerLiteral: propertyValue)
    }
}

Retrolux v1.0

Retrolux v1.0 is currently being designed and prototyped. It's primary goals are:

  1. Use Swift 4's Codable protocols instead of the pre-1.0 "Serializer" concept
  2. Use Swift 4's built-in JSONEncoder and JSONDecoder classes
  3. Enable extensible support for reactive frameworks (i.e., ReactiveCocoa)
  4. Simplify the code base by removing the complex BuilderArg logic
  5. Provide in-depth documentation and examples
  6. Further minimize the core of Retrolux, moving even more items and core functionality into plugins
  7. Simplify common workflow annoyances that we've encountered while using pre-1.0
  8. Make unit testing easier, and built-in instead of a duct-taped add-on like it was in pre-1.0

Currently, we are working on redesigning the Builder API towards accomplishing goals 3, 4, 6, 7, and 8.

Add support for persisted requests

Specifically, persisting the requests and sending them when the network becomes available. And coming up with a productive mechanism for notifying the GUI when the task is actually sent.

Related: background uploads/downloads

NestedTransformer.TypeOfProperty: Optionals Not Supported

They are actually supported, but it's hard to use and confusing.

I evaluated the code and realized why NestedTransformer's code appears to be stupid. tl;dr, delete the ? from typealias TypeOfProperty = NSNumber?.

    class OptionalAnyToOptionalNSNumberTransformer: NestedTransformer {
            typealias TypeOfData = Any?
            typealias TypeOfProperty = NSNumber? // Should be NSNumber, but most people will put in an optional.
            
            func setter(_ dataValue: Any?, type: Any.Type) throws -> NSNumber {
                if let number = dataValue as? NSNumber {
                    return number
                } else if let string = dataValue as? String, let integer = Int(string) {
                    return NSNumber(integerLiteral: integer)
                } else {
                    throw OptionalAnyToOptionalNSNumberTransformerError.unrecognizedNumber(given: dataValue)
                }
            }
            
            func getter(_ propertyValue: NSNumber) throws -> Any? {
                return propertyValue
            }
        }

Improve Parsing Error info

Current State:
When Retrolux is unable to parse the JSON, we get an error message and the entire response from the server via the response.data object.
Desired State:
Along with the retrolux generated error message, it would be nice to get the section of the server response that is not matching the retrolux object. This will improve error reporting and help speed up the debug process.

Create Call Class

TaskService taskService = ServiceGenerator.createService(TaskService.class);  
Call<List<Task>> call = taskService.getTasks();  
call.enqueue(new Callback<List<Task>>() {  
    @Override
    public void onResponse(Call<List<Task>> call, Response<List<Task>> response) {
        if (response.isSuccessful()) {
            // tasks available
        } else {
            // error response, no access to resource?
        }
    }

    @Override
    public void onFailure(Call<List<Task>> call, Throwable t) {
        // something went completely south (like no internet connection)
        Log.d("Error", t.getMessage());
    }
}

Retrolux v0.6.0

Plan:

  • Rework Reflectable property config (ignored, nullable, etc.)
  • Rework Reflectable transformers to be simpler and more powerful
  • Refactor code into smaller files (especially Builder.swift and Reflectable.swift)
  • Add comments to source code
  • Update README.md
//: Playground - noun: a place where people can play

import UIKit

enum PropertyCustomizations {
    case ignored
    case nullable
    case mapped(to: String)
    case transformed(TransformerType)
}

class Config {
    internal var storage = [String: [PropertyCustomizations]]()
    subscript(property: String) -> [PropertyCustomizations] {
        get {
            return storage[property] ?? []
        }
        set {
            storage[property] = newValue
        }
    }
}

protocol Reflectable: NSObjectProtocol {
    static func config(_ c: Config)
}

class Reflection: NSObject, Reflectable {
    class func config(_ c: Config) {
        
    }
}

protocol TransformerType {
    var propertyType: Any.Type { get }
    var dataType: Any.Type { get }
    
    func set(value: Any, propertyName: String, instance: Reflectable)
    func getValue(propertyName: String, instance: Reflectable) -> Any
}

class Transformer<PropertyType, DataType>: TransformerType {
    var propertyType: Any.Type {
        return PropertyType.self
    }
    
    var dataType: Any.Type {
        return DataType.self
    }
    
    private let setter: (DataType) -> PropertyType
    private let getter: (PropertyType) -> DataType
    
    init(setter: @escaping (DataType) -> PropertyType, getter: @escaping (PropertyType) -> DataType) {
        self.setter = setter
        self.getter = getter
    }
    
    func set(value: Any, propertyName: String, instance: Reflectable) {
        let transformed = setter(value as! DataType)
        (instance as! NSObject).setValue(transformed, forKey: propertyName)
    }
    
    func getValue(propertyName: String, instance: Reflectable) -> Any {
        return getter((instance as! NSObject).value(forKey: propertyName) as! PropertyType)
    }
}

class CustomTransformer<ClassType, PropertyType, DataType>: TransformerType {
    var propertyType: Any.Type {
        return PropertyType.self
    }
    
    var dataType: Any.Type {
        return DataType.self
    }
    
    init(setter: @escaping (ClassType, DataType) -> Void, getter: @escaping (ClassType, PropertyType) -> DataType) {
        
    }
    
    func set(value: Any, propertyName: String, instance: Reflectable) {
        
    }
    
    func getValue(propertyName: String, instance: Reflectable) -> Any {
        return () as Any
    }
}

let dateTransformer: TransformerType =
    Transformer<Date, String>(setter: { (value) -> Date in
        print("input: \(value)")
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd'T'hh:mm:ssZ"
        return formatter.date(from: value as! String)!
    }, getter: { (value: Date) -> String in
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd'T'hh:mm:ssZ"
        return formatter.string(from: value)
    })

class Person: Reflection {
    var name = ""
    var age = Data()
    
    var born = Date()
    
    override class func config(_ c: Config) {
        c["name"] = [.ignored]
        c["born"] = [.transformed(dateTransformer)]
        
        let customTransformer = CustomTransformer<Person, Data, Int>(setter: { (person, value) in
            person.age = Data()
        }, getter: { _ in
            Int()
        })
        c["age"] = [.nullable, .mapped(to: "user_age"), .transformed(customTransformer)]
    }
}

let config = Config()
let p = Person()
let type: Reflectable.Type = type(of: p)
type.config(config)
config["name"]

if case PropertyCustomizations.transformed(let transformer) = PropertyCustomizations.transformed(dateTransformer) {
    let value: Any = "2005-04-03T12:00:00Z"
    if type(of: value) == transformer.dataType || transformer.dataType == Any.self {
        transformer.set(value: value, propertyName: "born", instance: p)
    } else {
        print("Type \(type(of: value)) is not supported type. Should be \(transformer.dataType).")
    }
    print("person.born:", p.born)
    
    let gotBack = transformer.getValue(propertyName: "born", instance: p)
    print("Value back was: \(gotBack)")
}

Architecture

Arrows indicate direction of knowledge. I.e., if the arrow points from a left class to a right one, the left one knows about the right one, but the right one does not know about the left one. In other words, a class may use any other class that is "downstream," but not any that are "upstream."

img_20161002_231005

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.