These are chat archives for canjs/canjs

16th
Mar 2016
Mason Shin
@minsooshin
Mar 16 2016 01:10
is there a way that i can fire the ($click) event on the dom element?
in the component?
Kevin Phillips
@phillipskevin
Mar 16 2016 01:12
you mean trigger a click programatically?
Mason Shin
@minsooshin
Mar 16 2016 01:13
<td class="sa-expand-row" ($click)="toggleNestedContent(../../..)">
I have a stache file like this
but I would like to remove the click event listener from the component
Kevin Phillips
@phillipskevin
Mar 16 2016 01:14
ok
you just don’t want it in the template?
Mason Shin
@minsooshin
Mar 16 2016 01:14
events: {
  'tbody.sc-disabled td click’: function(el, ev): {
    …
  }
}
I am trying to do something like this
in the component
Kevin Phillips
@phillipskevin
Mar 16 2016 01:14
ok
Mason Shin
@minsooshin
Mar 16 2016 01:14
I wat to keep that event
but also want to fire the event for some cases
Thomas Sieverding
@Bajix
Mar 16 2016 01:15
You can pass events / the el
Mason Shin
@minsooshin
Mar 16 2016 01:15
more details are, that table is separate component I am using from another component
Kevin Phillips
@phillipskevin
Mar 16 2016 01:15
but also want to fire the event for some cases
Thomas Sieverding
@Bajix
Mar 16 2016 01:15
{toggleNestedContent} will be called w/ el, ev by default i believe
Kevin Phillips
@phillipskevin
Mar 16 2016 01:15
not sure what you mean by that
Thomas Sieverding
@Bajix
Mar 16 2016 01:16
You can also do ($click)=“toggleNestedContent($element, @event)"
Mason Shin
@minsooshin
Mar 16 2016 01:16
export default can.Component.extend({
  tag: 'sc-table',
  template: template,
  viewModel: ViewModel,
  helpers: {
    getColspan: function(options) {
      return this.attr('checkable') ?
        this.headerColumns().length + 1 :
        this.headerColumns().length;
    }
  }
});
I am defining table component like this
and this table domponent has the click event on the dom
export default can.Component.extend({
  tag: 'sc-grid',
  template: template,
  viewModel: viewModel,
  helpers: {
    showPaginationOnTop: function() {
      return this.paginationPosition === 'top';
    },

    showPaginationOnBottom: function() {
      return this.paginationPosition === 'bottom';
    }
  },

  events: {
   'tbody.sc-disabled td click': function(el, ev) {
      can.event.unbind.call(el, 'click', () => {
        console.log(this);
      });
      ev.preventDefault();
      ev.stopPropagation();
    }
  }
}
I am using that table component from this grid component
and I would like to remove click event on the dom for certain cases
then the table body has disabled class on it
Thomas Sieverding
@Bajix
Mar 16 2016 01:18
Your helpers won’t update unless you use this.attr(‘paginationPosition’)
Mason Shin
@minsooshin
Mar 16 2016 01:18
okay
but that is not my question...
Thomas Sieverding
@Bajix
Mar 16 2016 01:19
You can also do {{#is paginationPosition ‘top’}}{{/is}}
Kevin Phillips
@phillipskevin
Mar 16 2016 01:19
you don’t just want to put the if statement inside the toggleNestedContent function?
instead of removing the click handler
Thomas Sieverding
@Bajix
Mar 16 2016 01:19
Why do you want to unbind it?
Mason Shin
@minsooshin
Mar 16 2016 01:20
I am trying to figuring out the solution. I just tried unbind..
Thomas Sieverding
@Bajix
Mar 16 2016 01:20
It probably makes more sense to stop the propagation of the event
Mason Shin
@minsooshin
Mar 16 2016 01:20
it’s not working
both does’t work
stopPropagation doesn’t work, either
Thomas Sieverding
@Bajix
Mar 16 2016 01:21
You want to prevent a separate event handler from getting this same trigger or?
What’s your goal
Mason Shin
@minsooshin
Mar 16 2016 01:21
I am using generic table component
and the table has as column to expand nested table
Thomas Sieverding
@Bajix
Mar 16 2016 01:22
Your unbind won’t work as well, as you’d need to pass in the original function, among other reasons
Mason Shin
@minsooshin
Mar 16 2016 01:22
but when I remove a row data from the can.Model, I add disabled class on the row, and I would like to prevent the expanding event handler on the dom
but, when I click on the column, it still expands the nested table of the row
Thomas Sieverding
@Bajix
Mar 16 2016 01:23
So your problem is that when you click on a button in the row to remove an item, the event propagates and your delegate receives unintended events
correct?
Mason Shin
@minsooshin
Mar 16 2016 01:24
yes
I have the event on the dom with ($click) in the table component
I would like to prevent that event from grid component.
only for disabled rows
Thomas Sieverding
@Bajix
Mar 16 2016 01:25
Ah
but why does the grid component need a handler in the first place?
Kevin Phillips
@phillipskevin
Mar 16 2016 01:26
you want the handler to run on rows that don’t have the class disabled ?
Mason Shin
@minsooshin
Mar 16 2016 01:26
yes
Thomas Sieverding
@Bajix
Mar 16 2016 01:26
you could accomplish this with your delegate selector
Kevin Phillips
@phillipskevin
Mar 16 2016 01:26
so, why not just put that logic in your handler?
($click)=“toggleNestedContent(%element)”
Mason Shin
@minsooshin
Mar 16 2016 01:27
yeah, I think that is the best option
Thomas Sieverding
@Bajix
Mar 16 2016 01:27
Or, he could just do tbody.enabled click
Kevin Phillips
@phillipskevin
Mar 16 2016 01:27
yeah, in the events object
but not if it’s set up with ($click)
Thomas Sieverding
@Bajix
Mar 16 2016 01:28
Also, it’s worth noting that you can do this sort of thing directly within the click handler
Mason Shin
@minsooshin
Mar 16 2016 01:28
I am passing toggleNestedContent dispacher to the table component, too
Thomas Sieverding
@Bajix
Mar 16 2016 01:28
($click)=“attr(‘isExpanded’, false)"
Mason Shin
@minsooshin
Mar 16 2016 01:29
so I think event object may not work for it.
Thomas Sieverding
@Bajix
Mar 16 2016 01:29
It wouldn’t be difficult to manage this entirely by just manipulating the scope
Kevin Phillips
@phillipskevin
Mar 16 2016 01:29
I would try to avoid using the events object unless you need the performance of event delegation
Mason Shin
@minsooshin
Mar 16 2016 01:29
table component and grid component are not in the same application :)
Kevin Phillips
@phillipskevin
Mar 16 2016 01:30
it’s much easier to test if you use viewModel functions
Mason Shin
@minsooshin
Mar 16 2016 01:30
I like to use viewModel function for event in this case
since I need to pass the dispatcher to the component
thanks for all your help
Dovid Bleier
@dbleier
Mar 16 2016 14:32
@matthewp this worked perfectly!
var fn = ignore(function() { setTimeout(function{ .... } } )
fn(); // You'll get the real setTimeout
I will post my question and solution to the forum in line with my rant of the other day :)
:smile:
Kevin Phillips
@phillipskevin
Mar 16 2016 14:33
:+1:
Matthew Phillips
@matthewp
Mar 16 2016 17:23
Cool, glad it worked
Dovid Bleier
@dbleier
Mar 16 2016 18:42
next question. When using super-map with can-connect, if the Internet connection is down I get this error
can-wait.js:170 GET http://... net::ERR_INTERNET_DISCONNECTED
what I would expect is to fetch from the localstorage cache and render
then if data is retrieved from server, update the view
if not, just continue to display what is in the cache and continue to try to connection to the server
instead it just silently dies and renders nothing
Thomas Sieverding
@Bajix
Mar 16 2016 18:43
You’re talking about SSR?
Dovid Bleier
@dbleier
Mar 16 2016 18:43
no, I am not using ssr
client side render
stache
Thomas Sieverding
@Bajix
Mar 16 2016 18:43
;o
Dovid Bleier
@dbleier
Mar 16 2016 18:44
I think this is related to another issue which is even when I get data from server, it doesn't render with cached version first
it waits until it get the new data from server and then renders
a fundamental part of this project is the ability to run off a cached version of the data if the connection is down
Thomas Sieverding
@Bajix
Mar 16 2016 18:46
I haven’t worked w/ it yet, so I don’t have a basis to help you
Dovid Bleier
@dbleier
Mar 16 2016 18:47
ok, thanks for responding
Kevin Phillips
@phillipskevin
Mar 16 2016 18:47
are you using the fall-through-cache ?
Dovid Bleier
@dbleier
Mar 16 2016 18:47
yes
btw @phillipskevin nice piece on DI
Kevin Phillips
@phillipskevin
Mar 16 2016 18:48
thanks
can you put up a gist of what your connection code looks like?
Dovid Bleier
@dbleier
Mar 16 2016 18:50
ok
Christopher Oliphant
@RALifeCoach
Mar 16 2016 18:54
I am new to cans, please forgive me if this has been asked before. I took some existing code that must have used an older version of Constructor - a version I found online somewhere. I changed the Base to use Constructor and made changes up the tree of inheritance. However, in one of the modules it attempts to call this._super(), but told that this._super is undefined.
Thomas Sieverding
@Bajix
Mar 16 2016 18:55
@RALifeCoach super is a plugin
It’s really unnecessary though, as you can accomplish this with DI
IE, Base.prototype.foo.apply(this, arguments);
The existing code is just using Can + super. You can still use the latest & greatest just as well, all you need to do is set super as a dependency of can
What’re you using for DI? Steal/System/Require?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 19:01
@Bajix Thanks - I re-created the custom download including super and proxy and _super is now working
Thomas Sieverding
@Bajix
Mar 16 2016 19:01
@RALifeCoach np
Christopher Oliphant
@RALifeCoach
Mar 16 2016 19:02
I am not using DI - I am trying to gently modify a large existing code base
Thomas Sieverding
@Bajix
Mar 16 2016 19:03
@RALifeCoach I’d argue switching over to using DI is the first thing you’d want to do in order to revamp a legacy code base
Thomas Sieverding
@Bajix
Mar 16 2016 19:05
@dbleier You don’t need to import can/list, can/map, can/map/define/define etc
Dovid Bleier
@dbleier
Mar 16 2016 19:05
why not?
Thomas Sieverding
@Bajix
Mar 16 2016 19:06
They’re dependencies of the main can module
Dovid Bleier
@dbleier
Mar 16 2016 19:06
ok, but does it hurt?
on most of the examples/guides they do import
Thomas Sieverding
@Bajix
Mar 16 2016 19:07
Well, you put yourself through a lot of unnecessary effort
Kevin Phillips
@phillipskevin
Mar 16 2016 19:07
I normally just don’t import can
Dovid Bleier
@dbleier
Mar 16 2016 19:07
what effort?
is there a performance hit?
I think these imports are from the generator
Thomas Sieverding
@Bajix
Mar 16 2016 19:08
You’re frivelously including unnecessary dependencies, which creates maintenance headaches and leaves other developers confused
Dovid Bleier
@dbleier
Mar 16 2016 19:09
so why do the generators and guides use them?
and what is confusing about them?
Kevin Phillips
@phillipskevin
Mar 16 2016 19:10
they don’t import can
Thomas Sieverding
@Bajix
Mar 16 2016 19:10
It creates the impression that other developers should import can.List,can.Map etc within every module, when that’s simply not the case
Dovid Bleier
@dbleier
Mar 16 2016 19:12
I think I was told previously that it is best practice not to have implicit imports
Thomas Sieverding
@Bajix
Mar 16 2016 19:12
There are also times in which you’d want to depend on something internally, such as can/util/util but not can, in order to make a sane dependency tree
Dovid Bleier
@dbleier
Mar 16 2016 19:12
good point about can, not sure why that is there
ok, I'll take out can
but I don't think is the answer to my issue
:)
Thomas Sieverding
@Bajix
Mar 16 2016 19:13
yea I wasn’t paying attention to your question
What was it again?
All I saw was code, and the imports, and frowned
Kevin Phillips
@phillipskevin
Mar 16 2016 19:14
so, its the data in your supermap that is not rendering?
Dovid Bleier
@dbleier
Mar 16 2016 19:15
it's not initially rendering the cached version before fetching updates from server
it runs and pulls it into my sign.get()
but the stache render isn't firing
so in the event of no connection or the server returns an error, it dies - no render
Kevin Phillips
@phillipskevin
Mar 16 2016 19:22
I can’t see anything wrong with your code
maybe submit an issue with a link to the gist
Dovid Bleier
@dbleier
Mar 16 2016 19:24
ok, thanks
Kevin Phillips
@phillipskevin
Mar 16 2016 19:25
actually, I have a question
Dovid Bleier
@dbleier
Mar 16 2016 19:25
do you think because I am doing some post-processing before calling set(sign) that is affecting things?
Kevin Phillips
@phillipskevin
Mar 16 2016 19:25
you’re not using the <sign-model> anywhere?
Dovid Bleier
@dbleier
Mar 16 2016 19:25
no
I am calling Sign.getList from the signPromise prop
the tag is there from the generator
Kevin Phillips
@phillipskevin
Mar 16 2016 19:26
ok
I would think you need to use Sign.connection.getList to get the fall through cache data
or use the tag
Dovid Bleier
@dbleier
Mar 16 2016 19:28
I thought the point of super-map is that it puts those methods right into the Map
Kevin Phillips
@phillipskevin
Mar 16 2016 19:28
you’re probably right
Dovid Bleier
@dbleier
Mar 16 2016 19:29
I'll check again, but it seems that signPromise does return the cached version from the Promise
it's just not rendering the view
Kevin Phillips
@phillipskevin
Mar 16 2016 19:30
but if you’re online it does render?
Dovid Bleier
@dbleier
Mar 16 2016 19:31
yes, but not with cached data, only with server data -- and it takes a long time until it renders
I take it back -- it made the server call before resolving the promise and then returned the server data, not the cached data
Dovid Bleier
@dbleier
Mar 16 2016 19:39
not only that, but it is not updating the cache anymore
but it used to
Kevin Phillips
@phillipskevin
Mar 16 2016 19:40
I know this is a stupid question, do you know what changed?
Dovid Bleier
@dbleier
Mar 16 2016 19:40
no, I haven't made any changes to the model in a while
Kevin Phillips
@phillipskevin
Mar 16 2016 19:40
ok
might be a bug in a new version of can-connect
do you know what version you have?
Dovid Bleier
@dbleier
Mar 16 2016 19:41
how can I check?
I did recently try to upgrade donejs to 0.7.2
Kevin Phillips
@phillipskevin
Mar 16 2016 19:42
npm ls | grep can-connect
Dovid Bleier
@dbleier
Mar 16 2016 19:42
├─┬ can-connect@0.3.3
Kevin Phillips
@phillipskevin
Mar 16 2016 19:45
not super new
I would still recommend opening an issue
Dovid Bleier
@dbleier
Mar 16 2016 19:45
ok
should I try upgrading it first?
Kevin Phillips
@phillipskevin
Mar 16 2016 19:46
you can, yeah
Christopher Oliphant
@RALifeCoach
Mar 16 2016 19:47
@Bajix The goal is to slowly introduce canjs while changing as little of the code as possible
Dovid Bleier
@dbleier
Mar 16 2016 19:48
upgrade to 0.3.6 but didn't help
well, I cleared the cache, now I am back to where I started
promise returns cache version
updates cache with new data
renders new data
I guess the old cache had become corrupted
Kevin Phillips
@phillipskevin
Mar 16 2016 19:55
oh
that’s good, right?
Dovid Bleier
@dbleier
Mar 16 2016 19:57
I guess
but it doesn't help with the original problem
Kevin Phillips
@phillipskevin
Mar 16 2016 19:58
ok, I’m lost then
what was the original problem?
Dovid Bleier
@dbleier
Mar 16 2016 20:21
that it's not rendering cached data
and if there is no connection it dies with no render
Kevin Phillips
@phillipskevin
Mar 16 2016 20:24
oh, right
you get the cached data?
Dovid Bleier
@dbleier
Mar 16 2016 20:26
yes
Kevin Phillips
@phillipskevin
Mar 16 2016 20:27
if you just call set there, does it render?
and are you seeing the Loading… before that?
Dovid Bleier
@dbleier
Mar 16 2016 20:31
do you mean call set then return or call set and then do post processing?
no, I don't see Loading...
I also have a logger component in index.stache
it also doesn't get rendered until after sign data returns
Kevin Phillips
@phillipskevin
Mar 16 2016 20:34
ok, since you don’t see Loading, I would try removing everything from your signPromise getter
except the return statement
Dovid Bleier
@dbleier
Mar 16 2016 20:34
from signPromise or sign?
Kevin Phillips
@phillipskevin
Mar 16 2016 20:34
signPromise
Dovid Bleier
@dbleier
Mar 16 2016 20:35
but that code is needed to create the params needed to fetch the data
Kevin Phillips
@phillipskevin
Mar 16 2016 20:35
yeah, sorry, I would comment out the User.getList
Dovid Bleier
@dbleier
Mar 16 2016 20:35
ok, but I was having this issue before I wrote that code
also user is currently stored in localstorage, so it doesn't hit that code
Kevin Phillips
@phillipskevin
Mar 16 2016 20:36
ok
Dovid Bleier
@dbleier
Mar 16 2016 20:37
I took it out but no diff
Kevin Phillips
@phillipskevin
Mar 16 2016 20:37
ok
Dovid Bleier
@dbleier
Mar 16 2016 20:38
it sort of make sense I don't see Loading... since it grabs from local cache, it's too fast
but really the issue is the renderer is not getting called
seems to me that the server update call is preceding the render in the event queue
or that can-wait is waiting for the server update before rendering
Mason Shin
@minsooshin
Mar 16 2016 21:37
@phillipskevin @Bajix I did with CSS. pointer-events: none; when the model data destroyed. :)
something like this:
file.bind('destroyed', function() {
  let $tbody = $(`tbody[data-id="${id}"]`);
  $tbody.addClass('sc-disabled');
});
Thomas Sieverding
@Bajix
Mar 16 2016 21:38
@minsooshin pointer-events: none isn’t cross-browser
Also, direct dom manipulation like that is poor separation of concern
Modify state -> render based off of state
Mason Shin
@minsooshin
Mar 16 2016 21:42
cross browser includes IE?
Mason Shin
@minsooshin
Mar 16 2016 21:43
okay, then I am fine since we don’t support IE
but, I agree on the point of dom manipulation...
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:04
I believe I have a feature request
I do not want init to be called under some circumstances - in our case when running unit tests
Julian
@pYr0x
Mar 16 2016 22:08
what do you mean with "init"
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:15
the function init is called during module instantiation
But it does things in our code, that I don’t to have happen during unit testing
Julian
@pYr0x
Mar 16 2016 22:19
init on can.Constructor?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:20
can.extend(can.Construct, {
        constructorExtends: true,
        newInstance: function () {
            var inst = this.instance(), args;
            if (inst.setup) {
                inst.__inSetup = true;
                args = inst.setup.apply(inst, arguments);
                delete inst.__inSetup;
            }
            if (inst.init *&& !window.__karma__) {
                inst.init.apply(inst, args || arguments);
            }
            return inst;
        },
yes
Julian
@pYr0x
Mar 16 2016 22:20
this in only for karma
i think this is not what we want
Thomas Sieverding
@Bajix
Mar 16 2016 22:21
What does Karma have to do with this?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:21
yes - that’s why I would prefer a more generic approach
an option in Construct to skip ‘init'
Julian
@pYr0x
Mar 16 2016 22:22
lets more talk about, what is in your init, that you will not run in testing
maybe this is the wrong place
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:23
            this.window.ready(this.proxy(this.onPageReady));
            this.window.on('load', this.proxy(this.onPageLoaded));
            this.window.resize(this.proxy(this.onWindowResize));
            this.window.scroll(this.proxy(this.onWindowScroll));
            this.window.on('lessReady', this.proxy(this.onLessReady));
that’s in a low level module that most of our other code extends
Thomas Sieverding
@Bajix
Mar 16 2016 22:24
You can do those bindings within your can.Control btw
{window} lessReady
etc
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:25
that may be so, but I am trying to introduce canjs gently into a codebase of >100,000 lines of code
Thomas Sieverding
@Bajix
Mar 16 2016 22:25
Why don’t you want those to be setup when Karma is loaded?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:26
because they fire and produce unexpected results (crashes) during unit testing
Thomas Sieverding
@Bajix
Mar 16 2016 22:26
does that look something like cannot call createElement of undefined?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:26
we get all kinds of exceptions being thrown
Thomas Sieverding
@Bajix
Mar 16 2016 22:27
System.config({
  packages: {
    can: {
      map: {
        './util/util': './util/domless/domless'
      }
    }
  },
  meta: {
    jquery: {
      format: 'global',
      exports: 'jQuery',
      deps: [
        'can/util/vdom/vdom'
      ]
    }
  }
});
I suspect your issues would be fixed via configuring domless/vdom
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:29
our test environment is already established with over 5,000 tests written so far
Thomas Sieverding
@Bajix
Mar 16 2016 22:29
You’re already using Karma?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:29
we don’t use stealjs or any other DI
yes we use karma, jasmine and phantomjs
Thomas Sieverding
@Bajix
Mar 16 2016 22:30
I see
Nvm then, Phantom wouldn’t need that
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:31
without the batch I showed above, we get the unexpected crashes
with the patch everything works just fine
Thomas Sieverding
@Bajix
Mar 16 2016 22:31
What are the crashes you’re getting?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:32
I can’t remember the specifics - usually trying to access a property of an undefined or null object - often burried deep in the bowels of jQuery
thoughts?
Thomas Sieverding
@Bajix
Mar 16 2016 22:38
Well, the obvious question is if it makes more sense to address those underlying issues
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:39
in a code base of 100,000+ lines?
In a company that is always under pressure to do more and no time for a major rewrite?
Thomas Sieverding
@Bajix
Mar 16 2016 22:40
I’ve been there, believe me, but it pays for itself to take a more disciplined approach
Julian
@pYr0x
Mar 16 2016 22:41
i agree
Thomas Sieverding
@Bajix
Mar 16 2016 22:44
If a company is always under pressure to do more, than it’s an indication that they don’t know the difference between goals & systems, and find themselves constantly stumbling over the short sidedness of previous decisions, which in turn creates more pressure to do things quick and dirty
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:45
The fact of the matter is that a rewrite is not going to happen. The company execs are not going to go for it, regardless of how good an idea it might be.
This company is under pressure to do more because it is growing at a huge rate and unable to hire enough good resources to keep up with the growth
Thomas Sieverding
@Bajix
Mar 16 2016 22:46
You don’t need to do a rewrite here, but putting sane testing (and DI) in place is a huge step forward without rebuilding the core functionality
That’s all the more reason to pump the breaks and do this part right
Developers don’t want to work on a shit show project that doesn’t even have the fundamentals in place, and it’s discouraging to existing developers
It affects hiring, developer growth, productivity, stability and the product itself
There’s no such thing as growing too fast to be disciplined
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:48
You can preach at me all night about the benefits - and I will agree with you all night. However, that won’t change the reality of the situation at this company.
New systems are being built using canjs, stealjs, etc, but older legacy systems are not
Thomas Sieverding
@Bajix
Mar 16 2016 22:49
If that’s the case then they’re setting themselves up for failure
It is surprisenly easy to add those to legacy projects
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:51
alright - show me how to add this - if it is easy then I can make the case - if it means rewriting core code and changes to most, if not all modules then it just isn’t going to happen
Thomas Sieverding
@Bajix
Mar 16 2016 22:53
How is your project setup now?
Do files just load up and presume other variables are globally defined?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:53
For example, changing each module that extends the legacy version of Construct would mean changing 316 files with their associated unit tests
files load up and add themselves on the project namespace
Thomas Sieverding
@Bajix
Mar 16 2016 22:54
How so? Aren’t those all just using can.Control.extend?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:55
No - we have a version of Construct from many years ago
Except it is call Base in our code
In this version the code over writes the constructor, instead of init
Thomas Sieverding
@Bajix
Mar 16 2016 22:56
So then you only have one place, where base is defined
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:56
If a module doesn’t have a constructor, it will use the one from an inherited module, and so on
but the code we use extends slightly differently, requiring changes in all modules that inherit from it
I have created a cloned copy of the inheritance tree based on Can
and changed one module as a test
that’s how I know about the differences
the changes aren’t big - but little changes repeated enough times become big
Thomas Sieverding
@Bajix
Mar 16 2016 22:59
Ok, so you’re basically in the gutter because previously this was done in a hacky manor
Christopher Oliphant
@RALifeCoach
Mar 16 2016 22:59
using an early implementation of the code used by Can
it was all that was available at the time
Thomas Sieverding
@Bajix
Mar 16 2016 23:00
The issue is that your code isn’t DRY, to an embarassing degree
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:00
we also have a system that uses an early version of stealjs
that too would require extensive changes to make compatible with modern steal
Thomas Sieverding
@Bajix
Mar 16 2016 23:01
I don’t have a fix for you if your code isn’t DRY, but that’s certainly fixible w/ some effort
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:02
DRY???
Thomas Sieverding
@Bajix
Mar 16 2016 23:02
DRY = Don’t Repeat Yourself
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:03
thanks
Thomas Sieverding
@Bajix
Mar 16 2016 23:04
Multi File search/replace does help out with these things
But there’s no getting around the fact that you’ll need to do some cleanup to make things DRY just so that you have a point to start from
Fortunately that kind of work is very fast
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:07
actually the code isn’t bad in terms of not repeating - there are base modules that are used by the end modules for most of the system
those base modules contain the bulk of the functions used by the final modules
Thomas Sieverding
@Bajix
Mar 16 2016 23:07
So then you could just refactor the base modules
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:08
but that also creates acode pattern that will mean changing all the final modules
Thomas Sieverding
@Bajix
Mar 16 2016 23:08
Why would that be the case?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:09
The way the methods ‘constructor' and ‘init' are used is different from what they need to be going forward
I could try to use a lower level module to exchange the calls so that constructor and init end up being over rides for ‘init' and ‘setup’. While that might work, it would be misleading and confusing.
Thomas Sieverding
@Bajix
Mar 16 2016 23:11
How are they used differently?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:12
‘constructor' is called when the module is instated - just like ‘init’ is in the newer canjs code
‘init’ is called after the constructor is finished - somewhat like the ‘setup’ call in the new canjs code
and in some modules, init is over ridden and called when the form has finished loading
Thomas Sieverding
@Bajix
Mar 16 2016 23:14
You have that mixed up. constructor === setup, init === init
You should be able to do a multi-file search and replace for constructor -> setup
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:16
and I still have the problem of constructor calling init - because init is where many modules place ajax calls - and I want to mock the ajax calls so they don’t happen
Thomas Sieverding
@Bajix
Mar 16 2016 23:16
I see, so your modules don’t have proper lifecycles either
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:17
no they do not - remember this is 4 year old code
Thomas Sieverding
@Bajix
Mar 16 2016 23:17
The ajax issue is easy to fix
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:18
you can see how this rapidly becomes a can of worms
You need to fix this regardless, might as well do it proper. You’ll end up with a better outcome, and it’ll be easier to iterate on fixes
Use can.fixture to hijack your AJAX calls
Voila
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:23
can I tell fixtures to ignore all ajax calls or will I have to override each call?
(there are over 100 calls, plus images and other assorted types of file retrievals.)
You could override can.ajax
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:26
execpt the calls already exist using $.ajax
yes I could override $.ajax, but that’s also used by jasmine
Thomas Sieverding
@Bajix
Mar 16 2016 23:27
multi-file search & replace
$.ajax -> can.ajax
Do dedicated commits for stuff like that
squash later if desired
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:28
right
what about the window events firing?
Thomas Sieverding
@Bajix
Mar 16 2016 23:28
Comment it out, get things sorted out, then tackle that
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:29
I need a clear roadmap to the end of the journey before beginning
the lower level module that binds these events calls functions that are over ridden in the higher level modules
those modules would stop working
Thomas Sieverding
@Bajix
Mar 16 2016 23:30
If you commented out the binding?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:30
yes
that would be great for unit testing, but work break the working system
Thomas Sieverding
@Bajix
Mar 16 2016 23:31
So then what were trying to accomplish in the first place by disabling them during unit testing
We’re still at the break a few eggs phase here, take it one step at a time
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:32
because in unit testing they do not need to fire - in fact they break things when they do fire
Thomas Sieverding
@Bajix
Mar 16 2016 23:32
So solve that issue w/ fixtures
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:32
Yes, I can solve ajax with fixtures
how would I solve the events firing?
Thomas Sieverding
@Bajix
Mar 16 2016 23:33
If you solve ajax with fixtures, do you even need to prevent those from firing?
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:34
yes
absolutely yes
Thomas Sieverding
@Bajix
Mar 16 2016 23:35
Then add logic to only bind if it’s not a test
Christopher Oliphant
@RALifeCoach
Mar 16 2016 23:36
okay - that’s worth a try
I will spend some time on it and report back in a day or so
Thomas Sieverding
@Bajix
Mar 16 2016 23:38
k
I’ll be around if you get stuck