How can I make a lightning component change as the underlying data changes without refreshing?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
4
down vote

favorite












I'm writing a lightning page that allows two players to remotely play chess through the same lightning page. The page uses the aura framework.



For what I've already implemented, the Game__c object has two lookup fields to a user- one for each player- and only lets the correct player move a piece on their turn. Moreover, when the page loads, it loads the correct board position.



However, when a player moves a piece, the board does not update on their opponent's screen- the opponent has to refresh to see the update.



How can I make the board update in as soon as the active player makes their move?










share|improve this question







New contributor




SarcasticSully is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    4
    down vote

    favorite












    I'm writing a lightning page that allows two players to remotely play chess through the same lightning page. The page uses the aura framework.



    For what I've already implemented, the Game__c object has two lookup fields to a user- one for each player- and only lets the correct player move a piece on their turn. Moreover, when the page loads, it loads the correct board position.



    However, when a player moves a piece, the board does not update on their opponent's screen- the opponent has to refresh to see the update.



    How can I make the board update in as soon as the active player makes their move?










    share|improve this question







    New contributor




    SarcasticSully is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I'm writing a lightning page that allows two players to remotely play chess through the same lightning page. The page uses the aura framework.



      For what I've already implemented, the Game__c object has two lookup fields to a user- one for each player- and only lets the correct player move a piece on their turn. Moreover, when the page loads, it loads the correct board position.



      However, when a player moves a piece, the board does not update on their opponent's screen- the opponent has to refresh to see the update.



      How can I make the board update in as soon as the active player makes their move?










      share|improve this question







      New contributor




      SarcasticSully is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm writing a lightning page that allows two players to remotely play chess through the same lightning page. The page uses the aura framework.



      For what I've already implemented, the Game__c object has two lookup fields to a user- one for each player- and only lets the correct player move a piece on their turn. Moreover, when the page loads, it loads the correct board position.



      However, when a player moves a piece, the board does not update on their opponent's screen- the opponent has to refresh to see the update.



      How can I make the board update in as soon as the active player makes their move?







      apex lightning controller aura






      share|improve this question







      New contributor




      SarcasticSully is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      SarcasticSully is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      SarcasticSully is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 days ago









      SarcasticSully

      1233




      1233




      New contributor




      SarcasticSully is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      SarcasticSully is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      SarcasticSully is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          Very very interesting question.




          1. Using Platform Events and lightning:empAPI : This can be solved by Platform events, whenever a player makes a move, fire a platform event. Also as a listener use lightning:empAPI in both the components.

          When 1 player makes a move, the other player's components gets notified and he reacts accordingly by refreshing the view or moving that piece via code.




          1. Using Lightning Data Services: This might be another way to handle this. According to docs/DF18 session, LDS automatically uses streaming API so that all screens have fresh data, not sure how effective it is.





          share|improve this answer
















          • 1




            Seems promising, but [in both the components] -- is actually the instance of same component, so an event fired and subscribed sits on the same component, thus it may get complex as which User need to fire vs. which User need to subscribe to the event.
            – Jayant Das
            2 days ago










          • Can be bit challenging, but I have built something similar that the event though fires only the people who mentioned in will react to it.
            – Pranay Jaiswal
            2 days ago

















          up vote
          1
          down vote













          There is a new feature mentioned at DF 18 called Live Records, that will be part of Lightning Data Service, which I think is based on the new Change Data Capture feature, but I think it is only in Dev Preview right now:
          https://developer.salesforce.com/blogs/2018/08/what-is-change-data-capture.html



          If you look at this DF session, you'll see a demo of it doing pretty much what you are describing - user 1 is viewing a record and it is changed by another user - and the change will be automatically made on user 1's screen without requiring a refresh. So might be worth seeing if you can get access to that since you have a good use case there






          share|improve this answer




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "459"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            SarcasticSully is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f239531%2fhow-can-i-make-a-lightning-component-change-as-the-underlying-data-changes-witho%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            5
            down vote



            accepted










            Very very interesting question.




            1. Using Platform Events and lightning:empAPI : This can be solved by Platform events, whenever a player makes a move, fire a platform event. Also as a listener use lightning:empAPI in both the components.

            When 1 player makes a move, the other player's components gets notified and he reacts accordingly by refreshing the view or moving that piece via code.




            1. Using Lightning Data Services: This might be another way to handle this. According to docs/DF18 session, LDS automatically uses streaming API so that all screens have fresh data, not sure how effective it is.





            share|improve this answer
















            • 1




              Seems promising, but [in both the components] -- is actually the instance of same component, so an event fired and subscribed sits on the same component, thus it may get complex as which User need to fire vs. which User need to subscribe to the event.
              – Jayant Das
              2 days ago










            • Can be bit challenging, but I have built something similar that the event though fires only the people who mentioned in will react to it.
              – Pranay Jaiswal
              2 days ago














            up vote
            5
            down vote



            accepted










            Very very interesting question.




            1. Using Platform Events and lightning:empAPI : This can be solved by Platform events, whenever a player makes a move, fire a platform event. Also as a listener use lightning:empAPI in both the components.

            When 1 player makes a move, the other player's components gets notified and he reacts accordingly by refreshing the view or moving that piece via code.




            1. Using Lightning Data Services: This might be another way to handle this. According to docs/DF18 session, LDS automatically uses streaming API so that all screens have fresh data, not sure how effective it is.





            share|improve this answer
















            • 1




              Seems promising, but [in both the components] -- is actually the instance of same component, so an event fired and subscribed sits on the same component, thus it may get complex as which User need to fire vs. which User need to subscribe to the event.
              – Jayant Das
              2 days ago










            • Can be bit challenging, but I have built something similar that the event though fires only the people who mentioned in will react to it.
              – Pranay Jaiswal
              2 days ago












            up vote
            5
            down vote



            accepted







            up vote
            5
            down vote



            accepted






            Very very interesting question.




            1. Using Platform Events and lightning:empAPI : This can be solved by Platform events, whenever a player makes a move, fire a platform event. Also as a listener use lightning:empAPI in both the components.

            When 1 player makes a move, the other player's components gets notified and he reacts accordingly by refreshing the view or moving that piece via code.




            1. Using Lightning Data Services: This might be another way to handle this. According to docs/DF18 session, LDS automatically uses streaming API so that all screens have fresh data, not sure how effective it is.





            share|improve this answer












            Very very interesting question.




            1. Using Platform Events and lightning:empAPI : This can be solved by Platform events, whenever a player makes a move, fire a platform event. Also as a listener use lightning:empAPI in both the components.

            When 1 player makes a move, the other player's components gets notified and he reacts accordingly by refreshing the view or moving that piece via code.




            1. Using Lightning Data Services: This might be another way to handle this. According to docs/DF18 session, LDS automatically uses streaming API so that all screens have fresh data, not sure how effective it is.






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 days ago









            Pranay Jaiswal

            10.6k31950




            10.6k31950







            • 1




              Seems promising, but [in both the components] -- is actually the instance of same component, so an event fired and subscribed sits on the same component, thus it may get complex as which User need to fire vs. which User need to subscribe to the event.
              – Jayant Das
              2 days ago










            • Can be bit challenging, but I have built something similar that the event though fires only the people who mentioned in will react to it.
              – Pranay Jaiswal
              2 days ago












            • 1




              Seems promising, but [in both the components] -- is actually the instance of same component, so an event fired and subscribed sits on the same component, thus it may get complex as which User need to fire vs. which User need to subscribe to the event.
              – Jayant Das
              2 days ago










            • Can be bit challenging, but I have built something similar that the event though fires only the people who mentioned in will react to it.
              – Pranay Jaiswal
              2 days ago







            1




            1




            Seems promising, but [in both the components] -- is actually the instance of same component, so an event fired and subscribed sits on the same component, thus it may get complex as which User need to fire vs. which User need to subscribe to the event.
            – Jayant Das
            2 days ago




            Seems promising, but [in both the components] -- is actually the instance of same component, so an event fired and subscribed sits on the same component, thus it may get complex as which User need to fire vs. which User need to subscribe to the event.
            – Jayant Das
            2 days ago












            Can be bit challenging, but I have built something similar that the event though fires only the people who mentioned in will react to it.
            – Pranay Jaiswal
            2 days ago




            Can be bit challenging, but I have built something similar that the event though fires only the people who mentioned in will react to it.
            – Pranay Jaiswal
            2 days ago












            up vote
            1
            down vote













            There is a new feature mentioned at DF 18 called Live Records, that will be part of Lightning Data Service, which I think is based on the new Change Data Capture feature, but I think it is only in Dev Preview right now:
            https://developer.salesforce.com/blogs/2018/08/what-is-change-data-capture.html



            If you look at this DF session, you'll see a demo of it doing pretty much what you are describing - user 1 is viewing a record and it is changed by another user - and the change will be automatically made on user 1's screen without requiring a refresh. So might be worth seeing if you can get access to that since you have a good use case there






            share|improve this answer
























              up vote
              1
              down vote













              There is a new feature mentioned at DF 18 called Live Records, that will be part of Lightning Data Service, which I think is based on the new Change Data Capture feature, but I think it is only in Dev Preview right now:
              https://developer.salesforce.com/blogs/2018/08/what-is-change-data-capture.html



              If you look at this DF session, you'll see a demo of it doing pretty much what you are describing - user 1 is viewing a record and it is changed by another user - and the change will be automatically made on user 1's screen without requiring a refresh. So might be worth seeing if you can get access to that since you have a good use case there






              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                There is a new feature mentioned at DF 18 called Live Records, that will be part of Lightning Data Service, which I think is based on the new Change Data Capture feature, but I think it is only in Dev Preview right now:
                https://developer.salesforce.com/blogs/2018/08/what-is-change-data-capture.html



                If you look at this DF session, you'll see a demo of it doing pretty much what you are describing - user 1 is viewing a record and it is changed by another user - and the change will be automatically made on user 1's screen without requiring a refresh. So might be worth seeing if you can get access to that since you have a good use case there






                share|improve this answer












                There is a new feature mentioned at DF 18 called Live Records, that will be part of Lightning Data Service, which I think is based on the new Change Data Capture feature, but I think it is only in Dev Preview right now:
                https://developer.salesforce.com/blogs/2018/08/what-is-change-data-capture.html



                If you look at this DF session, you'll see a demo of it doing pretty much what you are describing - user 1 is viewing a record and it is changed by another user - and the change will be automatically made on user 1's screen without requiring a refresh. So might be worth seeing if you can get access to that since you have a good use case there







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                BritishBoyinDC

                8,8422762




                8,8422762




















                    SarcasticSully is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    SarcasticSully is a new contributor. Be nice, and check out our Code of Conduct.












                    SarcasticSully is a new contributor. Be nice, and check out our Code of Conduct.











                    SarcasticSully is a new contributor. Be nice, and check out our Code of Conduct.













                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f239531%2fhow-can-i-make-a-lightning-component-change-as-the-underlying-data-changes-witho%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?