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

Debugging enhancments (custom Messages and more ) #150

Merged
merged 11 commits into from
Sep 11, 2016

Conversation

Kanaye
Copy link
Collaborator

@Kanaye Kanaye commented Sep 6, 2016

Added a blocks.debug.throwMessage(Message: String, [method:object], [level: String]) function.
I don't like that we need to insert the 'method' object manualy if we wan't it to print usage.
Therefore the debug grunt tasks now inlines the Method object to a local variable ``__DEBUG_METHOD`.
I also don't like that because I had to add it to the .jshintrc, but I think it should fit until i come up with a better way (unless you have a better idea).

Also implemented that for failing async view initialization:
view-async

Array-observables that get reset with a non-nullish and non-array type: closes #116
array-reset

And the usage of non comment-able data-queries on comments:
comment-queries

Also if you ever tried to add a brakepint to an expression you know that it's not that easy...
Now it is (at least in the debug build):
That's a gif showing the initial expressions of the shopping example:
expression-debugging

Edit: Forgot to mention above, but the throwMessage-function will print a stack-trace if the method argument isn't supplied. Should help in most cases to understand where a message might be comming from.

@@ -61,7 +61,7 @@ module.exports = function (grunt) {
if (func) {
// FunctionExpression.BlockStatement.body(Array)
var funcBody = func.body.body;
esprima.parse('blocks.debug && blocks.debug.checkArgs(' + toValueString(data) + ', Array.prototype.slice.call(arguments), {})').body.forEach(function (chunk) {
esprima.parse('blocks.debug && blocks.debug.checkArgs(__DEBUG_METHOD, Array.prototype.slice.call(arguments), {}); var __DEBUG_METHOD = ' + toValueString(data) + ';').body.forEach(function (chunk) {
Copy link
Owner

Choose a reason for hiding this comment

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

I am shooting in the dark here but if you put the var declaration in the start would you need to add it to .jshintrc?

Something like: var __DEBUG_METHOD = ' + toValueString(data) + ';' blocks.debug && blocks.debug.checkArgs(__DEBUG_METHOD, Array.prototype.slice.call(arguments), {});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

escodegen generates code like that from it.
I'm not sure why but I can look into that this evening.
Here is a build of this pr showing that the code is generated like you mentioned above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahh got it! We are unshifting the chunks into the function, which means we are adding the parsed body reversed. I'll add a reverse before the foreach so it's more easy to read.

Regarding the .jshintrc:
jshint doesn't even check the generated code, the error is shown (if _DEBUG_METHOD is removed when checking the source (e.g. src/mvc/Application.js).

We might could "fix" this when we add something macro-ish build step like

//@throwDebug('mesage', 'type')
// which would be translated to something 
blocks.debug.throwMessage('message', __DEBUG_METHOD || null, 'type');

I'm not sure if I like that more.
We could implemted as a regex & replace function on the emitted code or with travelling through the ast and search & replace the matching nodes.

I'm not sure which of the methods is easier and less error prone.

What do you think ?

Copy link
Owner

Choose a reason for hiding this comment

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

You could do:

This is pseudo code. I haven't tested it. I hope you get the idea.

func.body.body.unshift.apply(
  func.body.body,
  esprima.parse('var __DEBUG_METHOD = ' + toValueString(data) + ';' blocks.debug && blocks.debug.checkArgs(__DEBUG_METHOD, Array.prototype.slice.call(arguments), {});').body
);

Regarding .jshintc - I leaving this to you to decide.

P.S. When you are ready with the changes you could go ahead and merge this yourself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I got it.
I'll think about the jshint thing and merge it when I'm done.

@astoilkov
Copy link
Owner

I have added some comments in the code.

Additionally, if you agree I want to give you push access to the repository. You can still work with pull requests to review our code. What do you think?

@Kanaye
Copy link
Collaborator Author

Kanaye commented Sep 7, 2016

I would love to get push access.
I will keep opening prs or contact you an other way so we can discuss bigger changes or new features.
Only small bug fixes and things like that I might commit directly.

@astoilkov
Copy link
Owner

Totally agree.

I gave you access. Happy coding and thanks a lot for all the help.

@Kanaye
Copy link
Collaborator Author

Kanaye commented Sep 7, 2016

Awesome thanks!
And you're welcome I really like jsblocks (and value) so it's also in my interest to make them better (or at least kill some bugs 😄 ).

Joscha Rohmann and others added 9 commits September 11, 2016 01:36
- Debug Build step now adds the method definition to a
  function-local-variable '__DEBUG_METHOD'.
- Added __DEBUG_METHOD to the .jshintrc.
- Added blocks.debug.throwMessage(Message: String, method: (e.g.
  __DEBUG_METHOD, level: [Notice, Warning, Error])
   Level currently only prints an other message and changes the color.
It's not perfect for example I don't like the __DEBUG_METHOD "global" in
the jshintrc but it's the best and cleanest way I could come up with for
now.
Other approches involved scary Estree-Magic and wold fail in case of
errors e.g. in user inserted function (callbacks).
For now it should be enough.
[]-observable-reset and usage of not comment-ready data-queries in
comments.
Views can not be constructed / added after the application has been
started. Try to add your views synchronous before document.readyState is
"complete".
Usage in a comment:

//@debugMessage('message', [Error|Warning|Info])

very basic manipalution of the estree but should do it for now.
Also removed the __DEBUG_METHOD again from the .jshintrc
The shopping example took about 3.8 seconds for the initial rendering due to garbe collection and
allocation of our inlined '__DEBUG_METHOD' object.
I speed it up at cost of more runtime memory (in the debug build) with
moving all the inline definitions to blocks.debug.methods object.
Every function now gets a unique id (just counting up).
Now it's arround 1.5 seconds.
print something (not paused and not executing).

This doesn't make the performance difference I hoped for because the
optimnization is within a 15-20% mark and that's within the general
js-engine noise. But it's at least fairly consistent and
array.prototype.slice.apply(arguments) is also slow in some enigines.

Optimizing the debug (and normal) build is on my private todo list.
@Kanaye
Copy link
Collaborator Author

Kanaye commented Sep 11, 2016

I optimized the performance of the debug build (see the 2 last commits for details) and implemented the mentioned macro.

The macro implementation is rather simple and not that flexible but we can change it later if decide we want to do more like that.
For now I think it's fine.

Here's what the macro can:

javascript //@debugMessage('message', Error);
would be compiled to
javascript blocks.debug.throwMessage('message', blocks.debug.methods(__METHOD_ID) || null, 'Error'); //@debugMessage('message', Error);

The second argument of the macro can be omitted and normal quoted can be used instead if single quotes.

I'll merge this now. Feel free to contact me if you have concerns (or questions) about something I merge (or commit to the master directly).

@Kanaye Kanaye merged commit 3102494 into astoilkov:master Sep 11, 2016
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.

DOM not updating correctly when reseting model with collection.
2 participants