Skip to content

Conversation

NathanaelA
Copy link
Contributor

I need this for my http://github.com/nathanaela/nativescript-livesync as it is needs to remove the last version of the page from the cache before it loads the newer version.

@ns-bot
Copy link

ns-bot commented Jun 2, 2015

Can one of the admins verify this patch?

@froyke
Copy link

froyke commented Jun 2, 2015

+1
Enhancing developer productivity is what will help build the {N} developers eco-system.
Live update might be the single most developer productivity enhancement.

@vzhen
Copy link

vzhen commented Jun 2, 2015

+1

@atanasovg
Copy link
Contributor

@NathanaelA Kudos for the live-sync effort! However I am not sure the proposed way of updating the application is safe. Clearing a single module cache may lead to unpredictable results within the app. For example there are modules that cache the exports of other modules. Imagine you clear a module that is already cached within other modules - in this case the other modules will use the older version. Or there are modules exposing events - such as the application module. Once you reload it, the event handlers will be lost.

What I may suggest here is to restart the entire application, in pretty much the same way we do it in our Companion Application. Here is a sample code:

    public static void restart(Context context) {
        Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_NEW_TASK);

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 123456, launchIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);

        // finish current activity and all below it first
        if (context instanceof Activity) {
            ((Activity)context).finishAffinity();
        }

        // kill the process explicitly (this is needed to reset the state of the V8 VM)
        // TODO: We may want to implement a "restart" routine in the runtime itself to enable such scenarios without killing the process
        android.os.Process.killProcess(android.os.Process.myPid());
    }
}

@NathanaelA

This comment was marked as abuse.

@NathanaelA

This comment was marked as abuse.

@froyke
Copy link

froyke commented Jun 3, 2015

While @atanasovg is correct and creating a function that could have weird behavior in the core runtime is not the ideal approach, the huge benefit of the live update for the {N} developer productivity must be weighted in.
May I suggest a middle ground here?
A hacky function with unstable consequences is not suitable for a core runtime, agreed. So, let's make sure we export enough hooks for client code to hack this behavior. In this case it looks like providing a simple getter for the loadedModules is all @NathanaelA needs in order to implement the clearCache functionality in his own code.

@NathanaelA

This comment was marked as abuse.

@froyke
Copy link

froyke commented Jun 4, 2015

@NathanaelA the point here is about the runtime engine and not about the live sync. Once the method is there future developers (and we are hoping for this platform to have a future, right?) will see this method and might be tempted to use it. The bad thing is that it'll actually work, but with weird edge cases.

It is ok for you to implement it, it is less desired for it to be implemented in the runtime - this is why I suggested the hooks, so you, me and everyone else can do all that crazy stuff.
And @NathanaelA - I don't consider release mode as an issue, as I feel this code should not even be present in release code and probably should be removed by the build process.

With all this theoretical discussion aside, I really suggest {N} maintainers to provide means for @NathanaelA to implement this LiveSync as I truly believe this is by far the most important single feature that {N} developers could have.

@NathanaelA

This comment was marked as abuse.

@mdgiles
Copy link

mdgiles commented Jun 16, 2015

+1

1 similar comment
@bfattori
Copy link

bfattori commented Jul 8, 2015

+1

@Plamen5kov Plamen5kov force-pushed the master branch 5 times, most recently from dc2cf97 to 5031087 Compare July 20, 2015 09:51
@weases
Copy link

weases commented Jul 29, 2015

+1

4 similar comments
@benchik
Copy link

benchik commented Aug 6, 2015

+1

@grabcode
Copy link

grabcode commented Sep 8, 2015

+1

@vicentedealencar
Copy link

+1

@atul221282
Copy link

+1

@blagoev
Copy link
Contributor

blagoev commented Sep 30, 2015

@NathanaelA
We are planning on improving the livesync CLI command that does not require this functionality which is not safe in many ways stated above by @atanasovg
Check this video https://goo.gl/p5ZpvW of what we up to.

Also there is API for page navigation without history NativeScript/NativeScript#548
and ways to clear the history NativeScript/NativeScript#283 that will be included in the 1.4 release

Closing this pull.

@blagoev blagoev closed this Sep 30, 2015
@NathanaelA

This comment was marked as abuse.

@blagoev
Copy link
Contributor

blagoev commented Oct 8, 2015

@NathanaelA
First let me reiterate why we choose to close this.

What you are doing is potentially dangerous code with many side effects. We want to state clearly that such code will not go into the core runtime in any circumstances. The code you are proposing does not take into account multiple things like state of Javascript GC, state of Java GC, module dependencies, require preconditions, state of the native instances, background operations etc. The last thing we want is non deterministic engine which does not provide any guarantee of its operation regardless of the current mode of execution - release or debug. Let me repeat that - the engine we are building should provide deterministic behavior in Release and in Debug mode. Hoping that nothing bad happens is not the best approach when building a software.

The commands you designate as "dangerous" (the double underscore commands) are very deterministic and have very predictable results. They are in fact "internal". That's why we designate them with double underscore. We want to be able to change the name, remove them, introduce new ones without introducing braking changes.

Now your work is inspiring indeed. Your contribution to NativeScript is invaluable. You will agree with us that is in the best interest for all of having the freedom to reject introducing bad code in the core runtime. What you prove is that LiveSync is major feature and the comments here show we need to do better job for it. We have started working on such improvements as shown in the video. Also we are looking into more deeper deterministic ways to handle js code sync but nothing major to show yet.

We choose to close this pull for the better. Don't judge us too hard for that.

Cheers,
blagoev

@NathanaelA

This comment was marked as abuse.

@blagoev
Copy link
Contributor

blagoev commented Oct 9, 2015

@NathanaelA - Thats the spirit Nathanael. Your contribution to {N} is invaluable. And to the {N} community as well.

@gordonpro
Copy link

😀

@sushruth
Copy link

👍

1 similar comment
@kazemihabib
Copy link

+1

@kazemihabib
Copy link

kazemihabib commented Jun 27, 2016

@blagoev in your video It shows that updates with out any restart but when using nativescript-angular livesync restarts the app every time, is there any plans to fix this?

@Kobzol
Copy link

Kobzol commented Jun 30, 2016

I̶t̶ ̶s̶h̶o̶u̶l̶d̶ ̶n̶o̶t̶ ̶r̶e̶s̶t̶a̶r̶t̶ ̶i̶f̶ ̶y̶o̶u̶ ̶o̶n̶l̶y̶ ̶e̶d̶i̶t̶ ̶c̶s̶s̶ ̶o̶r̶ ̶x̶m̶l̶ ̶(̶t̶e̶m̶p̶l̶a̶t̶e̶)̶ ̶f̶i̶l̶e̶.̶ ̶I̶f̶ ̶y̶o̶u̶ ̶e̶d̶i̶t̶ ̶a̶ ̶J̶S̶/̶T̶S̶ ̶f̶i̶l̶e̶ ̶(̶p̶o̶s̶s̶i̶b̶l̶y̶ ̶w̶i̶t̶h̶ ̶a̶n̶ ̶i̶n̶-̶l̶i̶n̶e̶ ̶t̶e̶m̶p̶l̶a̶t̶e̶ ̶o̶r̶ ̶C̶S̶S̶ ̶s̶t̶y̶l̶e̶)̶,̶ ̶i̶t̶ ̶w̶i̶l̶l̶ ̶r̶e̶s̶t̶a̶r̶t̶.
Nevermind, it restarts my app even if I modify external CSS/XML, so that seems like an issue.

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.