-
Notifications
You must be signed in to change notification settings - Fork 210
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
implement importNewModule #294
Conversation
Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
@jywarren Once you approve we can work through the documentation for this since it is gonna be very important that we have good documentation on this since this is a bit tricky. |
Hmm, i see. In principle we should have the same formatting for both, but I understand what you mean -- we can't use any non-browser friendly code if we're just loading on the fly. What's an example of something that wouldn't work, to clarify? Thanks!! |
@jywarren something where we require get-pixels or any other module won't work |
The invert module would also not work like this unless we import es6 style |
@jywarren this gives me an idea that we should try to move our codebase to es6 over time |
Hmm, this may be a non-starter until we can figure out a way through this. We wouldn't want our modules to start fragmenting into node and non-node -- that's one of the core benefits of the whole library, you know? Let's brainstorm a bit. Are there replacements for real-time Or, could we make getPixels available through a non-require function? Wrap it? One more thing -- is there a reason we couldn't call this importModule instead of importNewModule? Simpler maybe! |
@jywarren Actually One good thing is that this affect the existing system, so we can keep publishing our own modules bundled with the library |
Actually If we see the use cases, inside a frontend only project which is not being built the cdn script can be used. If somebody is using the module in node then he can use it via npm. Also if somebody is building a frontend project with any service and downloading the package via npm, his build tool will build the module as well and the require will be replaced then... |
Looking into options here, but i'm worried about relying on something that's not so well proven: https://stackoverflow.com/questions/5168451/javascript-require-on-client-side |
What about wrapping |
@jywarren Actually One more thing, this is gonna be on the module maker's side. I mean we are not going to dynamically load our own module which is bundled with the source anyway. |
Basically what we are doing is that a dynamically loaded module is Stand-Alone and hence all the processing code needs to be inside the module. I fit uses get-pixels then it would have to include it with it's code. This also enables the developer to use any alternative to get-pixels module as well if they wish to |
@jywarren Maybe we can make a few npm packages like get-pixels available inside the module locally...you are right so if the person wants to use an alternative or any other module then he needs to bindle all the code in a script |
ok, let me think about this a bit sorry i'm doing work on the live PublicLab.org server right now... will circle back! Also, maybe @ryzokuken has some thoughts on convenience and usability on this topic? |
@jywarren Oh that is fine I'll pick some other issue for now and for this I'll just do the part to make get-pixels available locally in module |
@jywarren Also I am making pixelManipulation API locally accessible, I hope that's fine? |
@jywarren I came up with a refactor of the pixelManipulation API, // Inside Module
draw(input){
input.getPixels()
input.pixelManipulation(options)
} |
Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
@jywarren I just included all the apis we use in our modules on the input object so that any dynamically loaded module can use these, If any other piece of code is required it must be bundled with the module. |
OK, this is interesting! It is a breaking API change? What would the documentation look like to explain this with the |
@jywarren No I made sure this is not a breaking change!! I'll write up some documentation for this now, I was waiting for your approval only!! Great! |
Also @jywarren Since we use the naming importString for importing a string into the sequencer, importModule feels like doing that for a module, hence I named it importNewModule |
Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
@jywarren Please have a look I added documentation on how to do a dynamic module. |
Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
@jywarren I included all the changes, also I reconfigured my IDE to the style you suggested so all the files will follow the convention in the future. Once we are done with this, we can add the required tests in #293 . Following this I want to complete meta-modules and then add our new dynamic loading functionality in the cli as well(Here I am thinking a way where user does sequencer --add-from-npm sequencer-invert and this downloads the dependency and calls loadNewModule on it) |
Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
@jywarren can you please have a look at this too |
CONTRIBUTING.md
Outdated
Any Independent Module Must follow this basic format | ||
Image Sequencer is designed to be run either in the browser or in a Node.js environment. For dynamically loaded modules, that means that any uses of `require()` to include an external library must be compiled using a system like `browserify` or `webpack` to ensure browser compatibility. An example of this can be found here: | ||
|
||
https://github.com/tech4gt/image-sequencer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wait, shouldn't this be not image-sequencer but a specific module?
README.md
Outdated
The `loadNewModule` method can be used to import a new module inside sequencer. Modules can be downloaded via npm, yarn or cdn and are imported with a custom name | ||
### Importing an independent module | ||
|
||
The `loadNewModule` method can be used to import a new module inside sequencer. Modules can be downloaded via npm, yarn or cdn and are imported with a custom name. If you wish to load a new module at runtime, it will need to avoid usingrequire()-- unless it is compiled with a system like browserify or webpack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small typo here -- usingrequire
- and it can be great to use ` characters as you did with loadNewModule, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!
OK, a couple tiny changes, but otherwise do you think this is good to go? |
Thanks, Varun!!! |
@jywarren this is pretty much ready to go, after this is done first I will add tests for getStep which will close another big PR |
Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
OK, do you know why tests are failing? I think we are ready otherwise! |
@jywarren must have been a bug with travis, i reopened the pr and now it is fine!! |
OK, done! Great work!!! |
Yay!! |
@jywarren Not all, But very less work is required now!! Rebasing the other PR over this!! |
super
…On Wed, Jul 18, 2018 at 10:17 AM Varun Gupta ***@***.***> wrote:
@jywarren <https://github.com/jywarren> Not all, But very less work is
required now!! Rebasing the other PR over this!!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ0-R6_beuZMykXKbhHyMOBCLz5P5ks5uH0NWgaJpZM4UuEhT>
.
|
@jywarren this implements importNewModule functionality for both node and browser environments, in node it is as simple as
sequencer.importNewModule(name,options)
In browser the module maker must browserify the code before publishing it for frontend use. For example to use invert as a dynamically imported module it will look something like thisSigned-off-by: tech4GT varun.gupta1798@gmail.com