Created
April 14, 2016 05:47
-
-
Save vicentedealencar/695682fe6a92249854794e9e67967a66 to your computer and use it in GitHub Desktop.
inspired on react philosophy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For an introduction to the Blank template, see the following documentation: | |
// http://go.microsoft.com/fwlink/?LinkId=232509 | |
(function () { | |
"use strict"; | |
var app = WinJS.Application; | |
var activation = Windows.ApplicationModel.Activation; | |
app.onactivated = function (args) { | |
if (args.detail.kind === activation.ActivationKind.launch) { | |
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) { | |
// TODO: This application has been newly launched. Initialize your application here. | |
} else { | |
// TODO: This application was suspended and then terminated. | |
// To create a smooth user experience, restore application state here so that it looks like the app never stopped running. | |
} | |
args.setPromise(WinJS.UI.processAll()); | |
} | |
render() | |
}; | |
app.oncheckpoint = function (args) { | |
// TODO: This application is about to be suspended. Save any state that needs to persist across suspensions here. | |
// You might use the WinJS.Application.sessionState object, which is automatically saved and restored across suspension. | |
// If you need to complete an asynchronous operation before your application is suspended, call args.setPromise(). | |
}; | |
app.start(); | |
var appState = { | |
out: 'qwe' | |
} | |
var renderedNode = null | |
function render() { | |
var content = document.getElementById('app-content') | |
var node = createApp() | |
if (renderedNode) { | |
content.replaceChild(node, renderedNode) | |
renderedNode = node | |
} else { | |
content.appendChild(node) | |
renderedNode = node | |
} | |
} | |
function createApp() { | |
var ret = document.createElement('div') | |
var out = document.createElement('p') | |
out.innerText = appState.out | |
var button = document.createElement('button') | |
button.innerText = 'Click here !' | |
button.onclick = function () { | |
appState.out = appState.out + '!' | |
render() | |
} | |
ret.appendChild(out) | |
ret.appendChild(button) | |
return ret | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment