{"action":"opened","issue":{"url":"https://api.github.com/repos/ractivejs/ractive/issues/2440","repository_url":"https://api.github.com/repos/ractivejs/ractive","labels_url":"https://api.github.com/repos/ractivejs/ractive/issues/2440/labels{/name}","comments_url":"https://api.github.com/repos/ractivejs/ractive/issues/2440/comments","events_url":"https://api.github.com/repos/ractivejs/ractive/issues/2440/events","html_url":"https://github.com/ractivejs/ractive/issues/2440","id":140885028,"number":2440,"title":"How to keep a counting alive and render on page view here with stopwatch","user":{"login":"mdsumonbappi","id":7759962,"avatar_url":"https://avatars.githubusercontent.com/u/7759962?v=3","gravatar_id":"","url":"https://api.github.com/users/mdsumonbappi","html_url":"https://github.com/mdsumonbappi","followers_url":"https://api.github.com/users/mdsumonbappi/followers","following_url":"https://api.github.com/users/mdsumonbappi/following{/other_user}","gists_url":"https://api.github.com/users/mdsumonbappi/gists{/gist_id}","starred_url":"https://api.github.com/users/mdsumonbappi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdsumonbappi/subscriptions","organizations_url":"https://api.github.com/users/mdsumonbappi/orgs","repos_url":"https://api.github.com/users/mdsumonbappi/repos","events_url":"https://api.github.com/users/mdsumonbappi/events{/privacy}","received_events_url":"https://api.github.com/users/mdsumonbappi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-15T06:20:47Z","updated_at":"2016-03-15T06:20:47Z","closed_at":null,"body":"Hi there,\r\n\r\nI am new to Ractive.js. I have a stop watch where there is a button start. On click of it I have start the counting of time. Now I need to keep counting while a user will visit the other page. When the user will come to current page again then he can see the updated counting which will be still counting. I have done up to this that counting is continuing. But when user come again he need to click the button again. And once click the button again it is being faster counting. Can anybody please help me on this please? Here are my attempts below >>>\r\n\r\n**My view >>> **\r\n````\r\n<div id=\"stopWatch\" class=\"modal-footer\">\r\n\t\t\t<div class=\"form-group\">\r\n\t\t\t\t<div class=\"pull-left\">\r\n\t\t\t\t\tStopwatch: {{shours}} h: {{sminutes}} m: {{sseconds}} s\r\n\t\t\t\t</div>\r\n\t\t\t\t<button id=\"btnStart\" class=\"btn btn-primary\" type=\"button\" on-click=\"startStopWatch\">Start</button>\r\n\t\t\t\t<button id=\"btnReset\" class=\"btn btn-secondary\" type=\"button\" on-click=\"startStopWatch\">Reset</button>\r\n\t\t\t</div>\r\n\t\t\t<label class=\"pull-left stopWatch\">  Time Spent:</label>\r\n\t\t</div>\r\n````\r\n\r\n**My startStopWatch function >>>**\r\n\r\n````\r\nfunction startStopWatch(ev, cfg) {\r\n\t\tvar rjs = this || cfg.rjs;\r\n\t\tvar $btn = $(ev.node);\r\n\t\tvar btnText = $btn.text();\r\n\t\tvar sg;\r\n\t\tif (btnText === 'Start') {\r\n\t\t\t$btn.html('Stop');\r\n\t\t\tsg = new cmnDt.stopWatch();\r\n\t\t\tsg.start(rjs, sg);\r\n\t\t} else if (btnText === 'Stop'){\r\n\t\t\t$btn.html('Start');\r\n\t\t\tsg = ev.context.sw;\r\n\t\t\tsg.stop(rjs, sg);\r\n\t\t}\r\n\r\n\t\tif (btnText === 'Reset' && ev.context.sw) {\r\n\t\t\tsg = ev.context.sw;\r\n\t\t\tsg.reset(rjs, sg);\r\n\t\t\t$('#btnStart').html('Start');\r\n\t\t}\r\n\t}\r\n````\r\n\r\n**My stopWatch function >>>**\r\n\r\n````\r\nfunction stopWatch() {\r\n\r\n\t\t\tvar timer;\r\n\r\n\t\t\tfunction start(rjs, sw) {\r\n\t\t\t\tprintTime(rjs, sw);\r\n\t\t\t\ttimer = setInterval(function () {\r\n\t\t\t\t\tgetTime();\r\n\t\t\t\t\tprintTime(rjs, sw);\r\n\t\t\t\t}, 1000);\r\n\t\t\t}\r\n\r\n\t\t\tfunction getTime(rjs) {\r\n\t\t\t\tcurrentSeconds = currentSeconds + 1;\r\n\r\n\t\t\t\tif (currentSeconds === 60) {\r\n\t\t\t\t\tcurrentMinutes += Math.round((currentSeconds) / 60);\r\n\t\t\t\t\tcurrentSeconds = 0;\r\n\t\t\t\t} else if (currentSeconds === 60 && currentMinutes === 60) {\r\n\t\t\t\t\tcurrentMinutes = 0;\r\n\t\t\t\t\tcurrentSeconds = 0;\r\n\t\t\t\t\tcurrentHours += 1;\r\n\t\t\t\t}\r\n\t\t\t\tisPreviousStart = true;\r\n\t\t\t}\r\n\r\n\t\t\tfunction printTime(rjs, sw) {\r\n\t\t\t\trjs.set({'sw': sw,'sseconds': currentSeconds,\r\n\t\t\t\t\t'sminutes': currentMinutes, 'shours': currentHours});\r\n\t\t\t}\r\n\r\n\t\t\tfunction stop(rjs, sw) {\r\n\t\t\t\tclearInterval(timer);\r\n\t\t\t\tprintTime(rjs, sw);\r\n\t\t\t\t$('.stopWatch').text(' Time Spent: ' + currentMinutes + ' m : ' + currentSeconds + ' s.');\r\n\t\t\t}\r\n\r\n\t\t\tfunction reset(rjs, sw) {\r\n\t\t\t\tclearInterval(timer);\r\n\t\t\t\tcurrentSeconds = 0;\r\n\t\t\t\tcurrentMinutes = 0;\r\n\t\t\t\tcurrentHours = 0;\r\n\t\t\t\tprintTime(rjs, sw);\r\n\t\t\t}\r\n\r\n\t\t\treturn {\r\n\t\t\t\tstart: start,\r\n\t\t\t\tstop: stop,\r\n\t\t\t\treset: reset\r\n\t\t\t};\r\n\t\t}\r\n````"}}