tonylukasavage / triple

REPL for Titanium
MIT License
96 stars 21 forks source link

Added "watch" autoreload on local js update #49

Closed jasonkneen closed 10 years ago

jasonkneen commented 10 years ago

Added it as a param on the end of the local.js argument so

$ triple test.js watch $ triple test.js 2000 watch

On restart, the delay is retained so first example is the best for instant reload.

jasonkneen commented 10 years ago

One issue with this - any required commonJS modules don't get updated. If you update a required module it's js file is successfully copied into the app folders, but doesn't get reloaded so the old one is cached. A restart of triple fixes it.

tonylukasavage commented 10 years ago

I'll take a look at this tonight or tomorrow.

WRT your comment, I'm not aware of a way to invalidate the module cache in Titanium like you can in node.js, so that may be impossible. We'll have to work to make sure this limitation is minimally confusing, because I worry that the expectation will be that it handles this situation as well.

jasonkneen commented 10 years ago

yeh, I may have a workaround that some might consider a bit "hacky" ;)

Got a PoC working that changes the name of the commonJS module file when it's copied using the modified date. This means it appears in code fine e.g. require("/path/to/test3") etc but when it's copied will be something like "/path/to/test3_2389232932" etc. The change is done in the background so the user still sees the correct code pushed to the server.

Using this technique the file is reloaded successfully.

jasonkneen commented 10 years ago

I've added the workaround which seems to work - probably need to clean up the previous file which I'll do - but it works. Modify the commonJS file, edit the main file to case a reload and the changes are carried into the app.

jasonkneen commented 10 years ago

Re last commit, kind of prefer to change

jsjsutil.addToApp("path/to/file.js")

to

jsutil.addToApp({file: "path/to/file.js", preventCaching: true});

or similar.

Thoughts welcome!