Is there a way to reuse blockly code?
-
I've done a few Blockly programs with M5 and it's amazing how fast I can put together a prototype. I can write code that does amazing things without having to look up class methods or function arguments in the docs. I think this is the real strength of UIFlow that people overlook. You get to write working code instead of looking up docs.
But with all the good UIFlow has, I can't find a way to easily reuse what I've done before. I need to pull in pieces of block functions and pieces from prior programs and edit them to fit my need in the current project. So I find myself writing the same stuff over again.
The closest I see is the ability to create custom blocks and drop chunks of Python code into them from other projects/libraries. But this is not editable in Blockly, so I'm back to writing and editing Python code.
I even tried using an online instance with a desktop instance open simultaneously hoping I could copy/paste chunks between them, but no luck. I can only duplicate blocks inside the one UIFlow instance. I can't copy it from one and paste it into the other.
Is there a way to copy/paste pieces of Blockly between several files, or maybe import a Blockly m5f file into a current project? This would be very helpful if you want to write large apps and not re-invent the wheel every time you start a new one.
Maybe I'm just missing something and there is a way to do this?
-
There is no known working copy and paste system like you describe at the moment. The only current was is to create custom blocks containing your code chunks.
-
@ajb2k3 That's too bad. It would be of great value to have a way to create libraries of reusable code.
With Blockly you can get up and running really fast. But then you have to come to a screeching halt and start over with every new project.
-
I agree, it is sad. :(
There is hope, however! I opened up one of the .m5f files that is saved from UI Flow to learn that it is a hybrid json/xml file with all the blockly code represented in XML. I'm thinking of working up a simple script that could be run in browser to parse this data and allow you pull single blocks and merge them into another file.
The concept here is that you upload two files (library.m5f and project.m5f, for examples sake) and then you can pluck whole blocks from and to either file. This way your great new invention from project.m5f can be added to your library and your great work from the library can be added to your project.
It will be simple, dare I say crude, to start with but should help. Also, I did tinker with making a custom .m5b file and it's not that hard but not quite the same as having a pre-built set of routines you want to use all the time. I'll post more info here once I have anything worth playing with.