Coder Social home page Coder Social logo

Comments (3)

 avatar commented on September 26, 2024

This would be a huge improvement! I did a little proof of concept and here are the results:

Types

  • LayoutProperties struct that has all information about how to layout the Element
  • Layoutable protocol has a mutable({ get set }) LayoutProperties property
  • ElementType protocol extends Layoutable and has all the methods required to do the rendering
  • ParentElementType protocol for Element's that has children.
  • Element: a plain implementation of ElementType
  • Component<State>: only difference is that it now conform's to ElementType instead of extending Element

Extensions
the idea is that most of the methods on Element can be added as extension of Layoutable or ParentElementType.

  • For Layoutable
    • func width(width: CGFloat) -> Self
    • func height(height: CGFloat) -> Self
    • func direction(direction: Direction) -> Self
    • func flex(flex: CGFloat) -> Self
    • func childAlignment(alignment: ChildAlignment) -> Self
    • func selfAlignment(alignment: SelfAlignment) -> Self
    • func justification(justification: Justification) -> Self
    • func margin(edges: Edges) -> Self
    • func size(width: CGFloat, _ height: CGFloat) -> Self
  • For ParentElementType
    • func children(children: [ElementType]) -> Self

Challenges

  • We must avoid associated values in our protocol's. Associated values force you to use generics to infer the type of the children array and that is problematic if you want multiple different elements as your children. I don't know how we are going to tackle this, currently applyDiff has a property Self and that also requires to infer the type using generics.
  • We can't use mutating functions if we use protocol extensions
    schermafbeelding 2015-06-27 om 14 33 44
    schermafbeelding 2015-06-27 om 14 32 12 But there's a workaround for this:
    schermafbeelding 2015-06-27 om 14 34 44

This is just to start a discussion about how it's all going to work.

from few.swift.

joshaber avatar joshaber commented on September 26, 2024

This is great, thanks for starting to think through it!

I'm wondering what the motivation is for separating ElementType and Layoutable? It seems unlikely we'd need one without the other.

from few.swift.

 avatar commented on September 26, 2024

I'm wondering what the motivation is for separating ElementType and Layoutable? It seems unlikely we'd need one without the other.

Mostly because this was a proof of concept and the first thing i wanted to do was add protocol extensions for mutating the layout properties. I agree, we don't need Layoutable.

from few.swift.

Related Issues (20)

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.