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

Feature/factory steps #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

DanielIndie95
Copy link
Owner

@DanielIndie95 DanielIndie95 commented Jul 24, 2017

i dont know if it was better , maybe the parameter :

 IComponentFactoryCreatorStep next = null

was a mistake in the IComponentFactoryCreatorStep interface

{
string keyWord = SelectorUtils.GetKeyWordFromSelector(rootElement.Selector);
AutoElementData[] filteredChildren = rootElement.InnerChildrens
.Where(elm => !IsAppenderElement(elm))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use just

.Where(IsAppenderElement)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but its the opposite of IsAppenderElement

Copy link
Collaborator

@Meir017 Meir017 Jul 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, got mixed up

{
public interface IComponentFactoryCreatorStep : IComponentFactoryStep
{
IEnumerable<ComponentGeneratorOutput> InvokeStep(AutoElementData rootElement, IComponentFileCreator parent, IComponentFactoryCreatorStep next = null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in some of the cases parent is null but based on the signature it's not it clear that it could be null.
either make all null-able parameters be null-able or add overloads with less parameters.

A better solution might be to add to override the method in ComponentFactoryCreatorStep and add virtual methods with less parameters

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont understand the changes needed to be done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets do that refactoring after I can better understand the tests and we have better code coverage...

{
RunAppender(parentClassCreator, _classAppenderContainer.GetAppender(keyWord), current);
return GenerateClassesForElements(filteredChildren);
return true;
}

private IEnumerable<ComponentGeneratorOutput> GenerateClassesForElements(IEnumerable<AutoElementData> children, IComponentFileCreator parent = null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is only called once without the second parameter. It does not need the parameter IComponentFileCreator parent = null

{
RunAppender(parentClassCreator, _classAppenderContainer.GetAppender(keyWord), current);
return GenerateClassesForElements(filteredChildren);
return true;
}

private IEnumerable<ComponentGeneratorOutput> GenerateClassesForElements(IEnumerable<AutoElementData> children, IComponentFileCreator parent = null)
{
IEnumerable<ComponentGeneratorOutput> outputs = new List<ComponentGeneratorOutput>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use

new HashSet<ComponentGeneratorOutput>(new ComponentOutputComparer());

instead. it's cleaner

.ToArray();

IComponentFileCreator current = _container.GetFileCreator(keyWord);
IEnumerable<ComponentGeneratorOutput> outputs = GenerateClassesForElements(children, current, next);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use

new HashSet<ComponentGeneratorOutput>(new ComponentOutputComparer())

.Where(elm => !IsAppenderElement(elm))
.ToArray();
string keyWord = SelectorUtils.GetKeyWordFromSelector(selector);
return GenerateAppendersOutputs(keyWord, rootElement.InnerChildrens, next)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use

var outputs = new HashSet<ComponentGeneratorOutput>(new ComponentOutputComparer());
outputs.UnionWith(GenerateAppendersOutputs(keyWord, rootElement.InnerChildrens, next));
outputs.UnionWith(GenerateFileCreatorOutputs(selector, filteredChildren, keyWord, next));
return outputs;

if (!IsAddinElement(child))
{
IComponentFileCreator fileCreator = _container.GetFileCreator(child.Type);
if (fileCreator != null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileCreator is never null. if is doesn't find a creator it returns the default. (maybe create a NullFileCreator?)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileCreator could be null if you dont set anyone as default (when creating them) , maybe this case could happend in the tests - the builtinComponentsInserter makes sure there is a default

.ForEach(att => RunAppender(parentClassCreator, att, current));
var result = _creatorsSteps.FirstOrDefault(step => step.ShouldInvokeStep(current, parentClassCreator))
?.InvokeStep(current, parentClassCreator, this);
return result ?? new List<ComponentGeneratorOutput>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use

return result ?? Enumerable.Empty<ComponentGeneratorOutput>();

@@ -58,7 +58,6 @@ public virtual ComponentGeneratorOutput GenerateComponentClass(string selector,
.AddCtor(CreateCtor(className))
.SetClassName(className)
.SetNamesapce(NamespaceName)
.AddUsings(GetUsings(elements))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's one line 57, no need to add the usings twice

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didnt see that, you're right

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

Successfully merging this pull request may close these issues.

None yet

2 participants