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

Ignore internal properties in components #459

Merged
merged 2 commits into from
Aug 16, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,28 @@ private final class PluginizedVisitor: BaseVisitor {
override func visitPost(_ node: ClassDeclSyntax) {
let componentName = node.typeName
if componentName == currentPluginizedComponentName {
// Internal properties cannot be seen by the needle generated code, so leave them out
let filteredProperties = propertiesDict[componentName, default: []].filter { property in !property.isInternal }
let component = ASTComponent(name: componentName,
dependencyProtocolName: currentPluginExtensionGenerics.dependencyProtocolName,
isRoot: node.isRoot,
sourceHash: sourceHash,
filePath: filePath,
properties: propertiesDict[componentName, default: []],
properties: filteredProperties,
expressionCallTypeNames: Array(componentToCallExprs[componentName, default: []]).sorted())
let pluginizedComponent = PluginizedASTComponent(data: component,
pluginExtensionType: currentPluginExtensionGenerics.pluginExtensionName,
nonCoreComponentType: currentPluginExtensionGenerics.nonCoreComponentName)
pluginizedComponents.append(pluginizedComponent)
} else if componentName == currentNonCoreComponentName {
// Internal properties cannot be seen by the needle generated code, so leave them out
let filteredProperties = propertiesDict[componentName, default: []].filter { property in !property.isInternal }
let component = ASTComponent(name: componentName,
dependencyProtocolName: currentDependencyProtocol ?? "",
isRoot: false,
sourceHash: sourceHash,
filePath: filePath,
properties: propertiesDict[componentName, default: []],
properties: filteredProperties,
expressionCallTypeNames: Array(componentToCallExprs[componentName, default: []]).sorted())
nonCoreComponents.append(component)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ private final class Visitor: BaseVisitor {
let componentName = node.typeName
if componentName == currentEntityNode?.typeName {
let dependencyProtocolName = node.isRoot ? emptyDependency.name : (currentDependencyProtocol ?? "")

// Internal properties cannot be seen by the needle generated code, so leave them out
let filteredProperties = propertiesDict[componentName, default: []].filter { property in !property.isInternal }
let component = ASTComponent(name: componentName,
dependencyProtocolName: dependencyProtocolName,
isRoot: node.isRoot,
sourceHash: sourceHash,
filePath: filePath,
properties: propertiesDict[componentName, default: []],
properties: filteredProperties,
expressionCallTypeNames: Array(componentToCallExprs[componentName, default: []]).sorted())
components.append(component)
}
Expand Down
22 changes: 11 additions & 11 deletions Generator/Tests/NeedleFrameworkTests/Fixtures/ComponentSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class MyComponent: NeedleFoundation.Component<
MyDependency
> {

let stream: Stream = Stream()
public let stream: Stream = Stream()

var donut: Donut {
public var donut: Donut {
return Donut()
}

var sweetsBasket: Basket {
public var sweetsBasket: Basket {
return shared {
Basket(dependency.candy, self.donut)
}
}

var myChildComponent: MyChildComponent {
public var myChildComponent: MyChildComponent {
return MyChildComponent(parent: self)
}

Expand All @@ -44,36 +44,36 @@ protocol SomeNonCoreDependency: Dependency {
}

class SomeNonCoreComponent: NeedleFoundation.NonCoreComponent< SomeNonCoreDependency > {
var newNonCoreObject: NonCoreObject? {
public var newNonCoreObject: NonCoreObject? {
return NonCoreObject()
}
var sharedNonCoreObject: SharedObject {
public var sharedNonCoreObject: SharedObject {
return shared {
return SharedObject()
}
}
}

class MyRComp: BootstrapComponent {
var rootObj: Obj {
public var rootObj: Obj {
return shared {
Obj()
}
}
}

class My2Component: Component<My2Dependency> {
var book: Book {
public var book: Book {
return shared {
Book()
}
}

var maybeWallet: Wallet? {
public var maybeWallet: Wallet? {
return Wallet()
}

var myStore: MyStorage<MyStorageKey> {
public var myStore: MyStorage<MyStorageKey> {
return MyStorage()
}

Expand All @@ -98,7 +98,7 @@ class SomePluginizedComp: PluginizedComponent<
ADependency,
BExtension, SomeNonCoreComponent
>, Stuff {
var tv: Tv {
public var tv: Tv {
return LGOLEDTv()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PluginizedDependencyGraphExporterTests: AbstractPluginizedGeneratorTests {
XCTAssertTrue(generated.contains("import UIKit"))
XCTAssertTrue(generated.contains("import ScoreSheet"))
XCTAssertTrue(generated.contains("import TicTacToeIntegrations"))
XCTAssertTrue(generated.contains("private let needleDependenciesHash : String? = \"4b585865bab35437b0cbc60e9d74b1b1\""))
XCTAssertTrue(generated.contains("private let needleDependenciesHash : String? = \"86deb40d0ec1c9fc9fd5e5e8fc17a167\""))
XCTAssertTrue(generated.contains("// MARK: - Registration"))
XCTAssertTrue(generated.contains("""
registerProviderFactory(\"^->RootComponent->LoggedOutComponent\", factory1434ff4463106e5c4f1bb3a8f24c1d289f2c0f2e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import UIKit

class LoggedInComponent: Component<EmptyDependency>, LoggedInBuilder {

var scoreStream: ScoreStream {
public var scoreStream: ScoreStream {
return mutableScoreStream
}

Expand Down
4 changes: 2 additions & 2 deletions Sample/MVC/TicTacToe/Sources/Root/RootComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import UIKit

class RootComponent: BootstrapComponent {

var playersStream: PlayersStream {
public var playersStream: PlayersStream {
return mutablePlayersStream
}

var mutablePlayersStream: MutablePlayersStream {
public var mutablePlayersStream: MutablePlayersStream {
return shared { PlayersStreamImpl() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import UIKit

class RootComponent: BootstrapComponent {

var playersStream: PlayersStream {
public var playersStream: PlayersStream {
return mutablePlayersStream
}

var mutablePlayersStream: MutablePlayersStream {
public var mutablePlayersStream: MutablePlayersStream {
return shared { PlayersStreamImpl() }
}

Expand Down
Loading