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












4















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



























    4















    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

























      4












      4








      4








      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














      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













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 20:06









      SarcasticSullySarcasticSully

      1333




      1333






















          2 Answers
          2






          active

          oldest

          votes


















          5














          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
            Nov 15 '18 at 22:08











          • 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
            Nov 15 '18 at 22:21



















          1














          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',
            autoActivateHeartbeat: false,
            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
            });


            }
            });














            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









            5














            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
              Nov 15 '18 at 22:08











            • 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
              Nov 15 '18 at 22:21
















            5














            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
              Nov 15 '18 at 22:08











            • 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
              Nov 15 '18 at 22:21














            5












            5








            5







            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 Nov 15 '18 at 20:15









            Pranay JaiswalPranay Jaiswal

            14.2k32452




            14.2k32452








            • 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
              Nov 15 '18 at 22:08











            • 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
              Nov 15 '18 at 22:21














            • 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
              Nov 15 '18 at 22:08











            • 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
              Nov 15 '18 at 22:21








            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
            Nov 15 '18 at 22:08





            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
            Nov 15 '18 at 22:08













            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
            Nov 15 '18 at 22:21





            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
            Nov 15 '18 at 22:21













            1














            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




























              1














              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


























                1












                1








                1







                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 Nov 15 '18 at 21:39









                BritishBoyinDCBritishBoyinDC

                8,8772764




                8,8772764






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Salesforce Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    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

                    Guess what letter conforming each word

                    Port of Spain

                    Run scheduled task as local user group (not BUILTIN)