Skip to content

Conversation

@sampaioletti
Copy link

Wouter had to give this a go it was driving me crazy thinking about it. I think for a rough first stab it shows it can work pretty well. I was able to code the FB tutorial with full type support using vscode (it was pretty awesome) and compile it to vanilla js. Didn't have a chance to generate tests or anything, just wanted to see how it would fit in so you could say how you wanted it completed. I'll play with it a little more and actually run a fb encode to see if it works (it should, or at least be close).

A couple notes

  • Couldnt make the IDLOptions workout cleanly so modified the constructor for the JSGenerator...may not be what you want, but it worked to get it going, I was just having to modify too much code to make the opts work right.
  • I tried to make a typings file for flatbuffers.js and it wasn't working for me (haven't written one before) so I just converted flatbuffers.js to a .ts file with all the typings, we can generate a d.ts from this so we can go back to the way you wanted to do it
  • I'm not sure if there is a more elegant way to do the generator code, its a lot of if/else nonesense but it got the job done
  • Compiled flatc with VS 2015 with no errors
  • The resulting project compiles nicely with tsc so I think its close to working for demo purposes

Not definitive by any means, I'm neither an expert at FB or TS, but was meant as a way to kick this off. The only time I get mad at FB is when I have to use it without intellisense....but that could be just me (: Let me know how/if you want me to keep going.

-Sam

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@sampaioletti
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

fixed issues with 'this' not having intellisense, causing issue with
generic in test_generated.ts line 220, tsc is dropping the namespace
'flatbuffers' off of 'flatbuffers.Table' and recognizing it as 2
different types
Caused issues all all around including with webpack/browserify
@sampaioletti
Copy link
Author

Tested the flatbuffers.ts and generated.ts files in our project...worked like a champ

@sampaioletti
Copy link
Author

Changed the example to be compatible with the one in the flatbuffers/tests area. Both the flatc->generated js file and the flatc->generatedts->tsc->generatedjs files pass the flatbuffers/tests/JavaScriptTest.js suite good first start.

Had to make the __union method generic so that calling method would know
return value
fixed cast when type is boolean
Needs implementation check, just repeated writeIntXX methods
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

generally looks like the right direction, just needs a lot of cleanup :)

return WrapInNameSpace(def.defined_namespace, def.name);
}

std::string GetNameSpace(const Definition &def) {
Copy link

Choose a reason for hiding this comment

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


std::string GetNameSpace(const Definition &def) {
const Namespace *ns = def.defined_namespace;
const std::string &name = def.name;
Copy link

Choose a reason for hiding this comment

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

Why was this needed? There's already the function FullNamespace

@@ -0,0 +1,350 @@
// Run this using JavaScriptTest.sh
Copy link

Choose a reason for hiding this comment

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

don't see any types in this file, why is there a copy?
tsTest -> ts_test

@@ -0,0 +1,80 @@
// test schema file
Copy link

Choose a reason for hiding this comment

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

please just use all the existing files rather than making copies.


return SaveFile(GeneratedFileName(path_, file_name_).c_str(), code, false);
std::string filename = "";
if (ts) {
Copy link

Choose a reason for hiding this comment

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

yes, all these if-thens can use some cleanup. prefer to stick them in a table (see LanguageParameters in idl_gen_general.cpp for an example) where possible, and otherwise think how to represent the code with as few if-thens as possible by sticking them into functions where needed.

code += " }\n\n";
code += " this.bb.write" + MakeCamel(GenType(field.value.type)) + "(this.bb_pos + offset, value);\n";
std::string value = "value";
if (GenTypeName(field.value.type, true)=="boolean") {
Copy link

Choose a reason for hiding this comment

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

if (field.value.type.base_type == BASE_TYPE_BOOL)

@sampaioletti
Copy link
Author

Thanks yeah it was a late night hackathon style was meant to just see how
it would go and then it worked haha. I'll go through and have a look at
your comments. I'll delete the duplicate files I just copied so I'd have
Temps to work with until ready.

On Oct 21, 2016 5:07 PM, "Wouter van Oortmerssen" notifications@github.com
wrote:

@gwvo commented on this pull request.

generally looks like the right direction, just needs a lot of cleanup :)

In include/flatbuffers/code_generators.h
#4065 (review)
:

@@ -112,6 +112,22 @@ class BaseGenerator {
return WrapInNameSpace(def.defined_namespace, def.name);
}

  • std::string GetNameSpace(const Definition &def) {

please use spacing conform https://google.github.io/

styleguide/cppguide.html

In include/flatbuffers/code_generators.h
#4065 (review)
:

@@ -112,6 +112,22 @@ class BaseGenerator {
return WrapInNameSpace(def.defined_namespace, def.name);
}

  • std::string GetNameSpace(const Definition &def) {
  • const Namespace *ns = def.defined_namespace;
  • const std::string &name = def.name;

Why was this needed? There's already the function FullNamespace

In js/tsTest/JavaScriptTest.js
#4065 (review)
:

@@ -0,0 +1,350 @@
+// Run this using JavaScriptTest.sh

don't see any types in this file, why is there a copy?

tsTest -> ts_test

In js/tsTest/monster_test.fbs
#4065 (review)
:

@@ -0,0 +1,80 @@
+// test schema file

please just use all the existing files rather than making copies.

In src/idl_gen_js.cpp
#4065 (review)
:

@@ -59,7 +65,14 @@ class JsGenerator : public BaseGenerator {
code += exports_code;
}

  • return SaveFile(GeneratedFileName(path_, file_name_).c_str(), code, false);
  • std::string filename = "";
  • if (ts) {

yes, all these if-thens can use some cleanup. prefer to stick them in a
table (see LanguageParameters in idl_gen_general.cpp for an example)
where possible, and otherwise think how to represent the code with as few

if-thens as possible by sticking them into functions where needed.

In src/idl_gen_js.cpp
#4065 (review)
:

   code += "  var offset = this.bb.__offset(this.bb_pos, " + NumToString(field.value.offset) + ")\n\n";
   code += "  if (offset === 0) {\n";
   code += "    return false;\n";
   code += "  }\n\n";
  •  code += "  this.bb.write" + MakeCamel(GenType(field.value.type)) + "(this.bb_pos + offset, value);\n";
    
  •  std::string value = "value";
    
  •  if (GenTypeName(field.value.type, true)=="boolean") {
    

if (field.value.type.base_type == BASE_TYPE_BOOL)


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#4065 (review),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AIZod67DYiQahjqA5XocvcebdQpygPUhks5q2UWTgaJpZM4Kb6mW
.

@ghost ghost force-pushed the master branch 3 times, most recently from c65126c to 2616516 Compare December 12, 2016 23:54
@ghost ghost force-pushed the master branch 11 times, most recently from 48a7fb3 to 2a7a44b Compare December 13, 2016 02:02
@aardappel
Copy link
Collaborator

Status?

@sampaioletti
Copy link
Author

sampaioletti commented Jan 5, 2017 via email

@gwest7
Copy link

gwest7 commented Mar 3, 2017

@sampaioletti is this still on your list?

@sampaioletti
Copy link
Author

sampaioletti commented Mar 3, 2017 via email

@aardappel
Copy link
Collaborator

This is probably obsolete now that this was merged: #4232

@aardappel aardappel closed this Jun 5, 2017
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.

4 participants