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

Meow: Support more types in makePartialUpdate #342

Open
sliemeobn opened this issue Jul 9, 2024 · 0 comments
Open

Meow: Support more types in makePartialUpdate #342

sliemeobn opened this issue Jul 9, 2024 · 0 comments

Comments

@sliemeobn
Copy link
Contributor

Currently the ModelUpdater type is very limited, only allowing access to properties that are a Primitive.

This excludes a wide variety of property types, such as Optionals, RawRepresentables, References, or arrays of these types.

    public subscript<P: Primitive>(dynamicMember keyPath: WritableKeyPath<M, QueryableField<P>>) -> P {
        get {
            self.update.model[keyPath: keyPath].value!
        }
        set {
            self.update.model[keyPath: keyPath].value = newValue

            let path = M.resolveFieldPath(keyPath)
            self.update.changes[path] = newValue
        }
    }

A solution could be to constrain this access to PrimitiveEncodable & Codable instead of Primitive. However, the encodePrimitive() function is potentially throwing, which is not ideal in the set accessor.

Alternatively, we could add a lot of typed overloads similar to the ModelUpdateQuery.setField functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants