Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

feat(articles): Modify articles module to implement style guidelines. #1126

Merged
merged 1 commit into from
Jan 15, 2016

Conversation

rhutchison
Copy link
Contributor

Update the articles module to implement the style guidelines.

Much of this work is from @trainerbill - I sent him a PR so he can get credit for the work. If he doesn't merge and fix up #874 soon, then this is available.

Closes #874
Closes #339

@rhutchison rhutchison force-pushed the article-styleguide branch 2 times, most recently from d7c4ebb to 5fc33c5 Compare January 1, 2016 20:30
@rhutchison rhutchison closed this Jan 1, 2016
@rhutchison rhutchison reopened this Jan 1, 2016
@ilanbiala
Copy link
Member

@trainerbill are we using this PR or #874?

@@ -0,0 +1,19 @@
(function () {
Copy link
Member

Choose a reason for hiding this comment

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

@rhutchison We don't need this. It's just a duplication of article.client.service

Copy link
Member

Choose a reason for hiding this comment

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

Ok. I see you removed articles.client.service. However, why add it to a models folder & rename with .model.js?

Also, the name should ArticleService to follow John Papa's guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it's a model, not a service.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, symantically speakijg, it's a model. However, we're treating it as a service; the $resource object is ambigious as to whether it's a model or service. And now this moves a file around, and adds a new directory to our structure.

I just don't see the point in this change if we're not modifying the implementation here. Why even introduce it, just for the sake of making a point that its a model.

I would rather wait, and address client-side models. We'll then be able to take part in a meaningful discussion, rather than tacking on a new idea that isn't relevant to the current PR.

If everyone else is fine with it, then I'll support it. I wanted to at least point it out, and get feedback from others.

@codydaig @ilanbiala @lirantal

Copy link
Member

Choose a reason for hiding this comment

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

I'd say if Angular calls it a service, so should we. Let's not change it just because it matches server-side wording or whatever else cosmetic reason we may have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, angular calls it a factory, not service. If we are going to have this rigid way of thinking, then menu's should be menuRun?

The style guide leaves this type of detail up to interpretation.

@trainerbill
Copy link
Contributor

Close 874. It's messed up and I am out for a few days.

controller: 'ArticlesController',
controllerAs: 'vm',
resolve: {
articleResolve: newArticle
Copy link
Member

Choose a reason for hiding this comment

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

At first glance I thought these all resolved to the same thing. @trainerbill says it saves a little code, but it isn't clear and it makes more sense to just call this the 1-2x necessary in the controller. @mleanos @rhutchison @lirantal @codydaig any other suggestions? This saves a couple lines but it is easy mistaken for the same injection and it just moves the code if it is only used one or two times.

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind how it is, now that I understand it. When I was looking at this a while back, it was really confusing to me. I don't think it's necessary, but it's probably ok. However, I know others will be confused as well; especially when just looking at the controller code.

It does feel a little weird to have logic, that seemingly belongs in the controller, in the route config when it's not really resolving any data; but just an empty new instance of an Article.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure I understand the concern? We are resolving a new instance of an article which is being injected to the controller. Unless you want to have a separate controller for create vs edit/view, you need to resolve something. One can argue that you can resolve null and then check for null in the controller and instantiate there, but what is the point when you can avoid it? Adding another controller will just duplicate code.

Copy link
Member

Choose a reason for hiding this comment

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

@rhutchison in one place, you resolve newArticle -> articleResolve, and in another getArticle -> articleResolve, and they are both referenced as article in the controller...that's confusing because you have to know the state as well when you are writing code. I'd rather not do that.

For reference L29 and L41 in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They both return a model of the same type - one is instantiated, the other is retrieved from the server.

articleResolve is Article in both cases

Copy link
Member

Choose a reason for hiding this comment

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

Can we add a comment here so people diving into the code knows what is going on?

Copy link
Member

Choose a reason for hiding this comment

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

Honestly I think it makes sense just to do this in the controller. It's less confusing and self-documenting that way.

Copy link
Contributor

Choose a reason for hiding this comment

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

One additional benefit is to share the resolved value among nested views. I use nested views all the time, so if I pass the Article in the resolve then populate it in one controller that value gets shared among my other views and controllers. If you instantiate the model in the controller the nested views would not get that data. I think we should start looking at nested views for much of the project and this is a good start.

Copy link
Member

Choose a reason for hiding this comment

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

@trainerbill I think I like what you're saying. However, I have a couple questions..

  1. Are you sharing the resolved data among multiple child states?
  2. Do your nested views have their own states, and/or controllers?

Can you elaborate on the use case of your nested views, or give an example (or gist) of what this implementation looks like?

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Yep
  2. Sometimes. You can define a new controller otherwise it inherits the parents. Also inherits all the resolves.

This is just off the top of my head:

https://gist.github.com/trainerbill/f51897d1a1e9ab5eaf26

So in my layout.html default server file i have

and ui-view="main"

I target main:

https://gist.github.com/trainerbill/f51897d1a1e9ab5eaf26#file-gistfile1-txt-L12

And put a layout file in it. This is a 2-4 column grid with 4 rows all with new ui-views like fluid-col-1-row-1 that I can now target in my nested states. Its tough to explain because articles is basic, but if we also wanted to save references with the article then we can have separate views that show the reference information and since it is using articleResolve it is shared so when the main article is saved so are the references.

Here is an abstract route that just resolves the article:
https://gist.github.com/trainerbill/f51897d1a1e9ab5eaf26#file-gistfile1-txt-L48

Now on the edit route my one view has the SaveArticleController which has the saving logic
https://gist.github.com/trainerbill/f51897d1a1e9ab5eaf26#file-gistfile1-txt-L84

and the references has no controller because it is using the ResolveArticleController, which just sets vm.article = articleResolve and so now both views have article resolve. If I update anything in one the other gets the update.

I think we need to move to nested views across the whole project and need to bring it up for discussion. It allows you to reuse views all over the place. For instance if I have a author module then I can use the view article easily, by resolving the article in the route and copy and pasting the view. done.

@ilanbiala
Copy link
Member

@rhutchison nice progress. Definitely some fixes made that aren't in #874. One thing that I'm not sure about, does it make sense to split the CRUD across multiple controllers? I feel like it segments the code a little.

@mleanos
Copy link
Member

mleanos commented Jan 2, 2016

@rhutchison I've pulled this branch down & tested it. Everything seems to be working as expected. I think we're close on this.

Why are some of the client tests disabled?

Lastly, I don't think we should go with the new models directory, and changing the name of the file to .model.js. I know this isn't truly a service, but rather a model. However, it's still functioning like a service at the moment; nothing has changed so why make this change now? I don't see the point even If it's only to prepare for the use of models on the client-side. As well, I don't see it making anything else any more clear to our users.

@rhutchison
Copy link
Contributor Author

One thing that I'm not sure about, does it make sense to split the CRUD across multiple controllers? I feel like it segments the code a little.

@ilanbiala If you are referring to ListController vs Controller, I would say that it absolutely makes sense for lists vs model. If you just look at the controllers, you will notice there is no overlap - a lot of extra bindings. When the list controller gets more functionality later, you will continue to see they are unrelated (bulk functionality, sorting, filters, etc.)

@rhutchison
Copy link
Contributor Author

Why are some of the client tests disabled?

@mleanos I fixed 2 of the 3. The 3rd I am not exactly sure how to implement atm, so I'll leave it there as a reminder/todo.

@rhutchison rhutchison force-pushed the article-styleguide branch 2 times, most recently from 9b95a2d to 7677ff6 Compare January 2, 2016 06:43
Update the articles module to implement the style guidelines.

Much of this work is from @trainerbill

Closes meanjs#874
Closes meanjs#339
@mleanos
Copy link
Member

mleanos commented Jan 2, 2016

Tested, and this LGTM. Thank you Ryan!!

@codydaig codydaig added this to the 0.5.0 milestone Jan 3, 2016
@codydaig
Copy link
Member

codydaig commented Jan 3, 2016

Made a suggestion to add a comment where there seems to be a point of confusion for people. Overall, LGTM. Nice work!

@ilanbiala
Copy link
Member

@lirantal LGTY?

@mleanos
Copy link
Member

mleanos commented Jan 15, 2016

@codydaig @ilanbiala Can we get this merged? It's been sitting for almost two weeks.

I don't think there's anything else up for debate here. Cody's suggestion for a comment for clarification isn't that vital; and I think users will be able to figure it out by just looking at the route configs, even though it's not really clear from just the controller.

I don't mean to be pushy, but we're so close to the finish line with the style-guide. Also, I've been putting off a PR while waiting for this.

@codydaig
Copy link
Member

@mleanos @lirantal @ilanbiala I'm cool with getting this merged. I think @ilanbiala is on board as well, just waiting final approval from @lirantal.

@ilanbiala
Copy link
Member

@codydaig let's just merge this and if @lirantal has suggestions, we'll do a new PR.

codydaig added a commit that referenced this pull request Jan 15, 2016
feat(articles): Modify articles module to implement style guidelines.
@codydaig codydaig merged commit 6c5b630 into meanjs:master Jan 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants