These are chat archives for canjs/canjs

9th
Jan 2017
Sunil George
@georgesunil81
Jan 09 2017 22:17
This may be a naive question, but I want to ask anyways to see if there is a best practice recommendation. I have a controller (can.Control) in my CanJS application that is quite bloated with over 2000 lines of code. Is there a way to break certain logically related methods out into a separate js file and import it or something? I am using AMD modules.
Kevin Phillips
@phillipskevin
Jan 09 2017 22:18
a naive answer is yes, but without knowing what that code does, it’s hard to say how
why is your controller doing so much?
sort of a rhetorical question, but something you should ask yourself
Sunil George
@georgesunil81
Jan 09 2017 22:19
@phillipskevin . Thanks. The can.Control has many event handler methods since the page it is rendering is rather element rich.
Kevin Phillips
@phillipskevin
Jan 09 2017 22:20
so maybe some of those should be in their own components
(or controls if that’s your thing)
Sunil George
@georgesunil81
Jan 09 2017 22:21
Yeah, it could have been done that way. Right now, there is only one controller that renders and controls that element rich page. So, I am trying to see if I can put some related methods out to seperate js files and AMD-import it.
Kevin Phillips
@phillipskevin
Jan 09 2017 22:22
sure
I don’t know that it’s going to make it easier to read your code though
not as much as actually breaking down the functionality into multiple stand-alone pieces
but you can take any event handler and move it to its own file
Sunil George
@georgesunil81
Jan 09 2017 22:24
Yeah, that is what I have to balance between - readability/maintainability vs "too many" lines of code.
Thanks @phillipskevin for the insights there. Will do.
Kevin Phillips
@phillipskevin
Jan 09 2017 22:25
if your event handlers are using this, you’ll need to figure out how to bind those functions if you import them
Sunil George
@georgesunil81
Jan 09 2017 22:44
Yes, some of the event handlers do refer to this! Thanks @phillipskevin for the pointer.