<commit_before>var mercury = require("mercury")

var FrameList = require("./views/frame-list")
var FrameEditor = require("./views/frame-editor")
var FrameData = require("./data/frames")

// Load the data
var initialFrameData = FrameData.load()

// Create the default view using the frame set
var frameList = FrameList(frames)

var state = mercury.hash({
    frames: mercury.hash(initialFrameData),
    editor: mercury.value(frameList)
})

// When the data changes, save it
state.frames(frameData.save)

// Show the frame editor
frameList.onSelectFrame(function (frameId) {
    var editor = FrameEditor(state.frames[frameId])

    state.editor.set(editor)

    editor.onExit(function () {
        // Restore the frame list
        state.editor.set(frameList)
    })
})

function render(state) {
    // This is a mercury partial rendered with editor.state instead 
    // of globalSoup.state
    // The immutable internal event list is also passed in
    // Event listeners are obviously not serializable, but 
    // they can expose their state (listener set)
    return h(state.editor.partial())
}

// setup the loop and go.
mercury.app(document.body, render, state)<commit_msg>Use two values in the state for editor & frameList<commit_after>var mercury = require("mercury")

var FrameList = require("./views/frame-list")
var FrameEditor = require("./views/frame-editor")
var FrameData = require("./data/frames")

// Load the data
var initialFrameData = FrameData.load()

// Create the default view using the frame set
var frameList = FrameList(frames)

var state = mercury.hash({
    frames: mercury.hash(initialFrameData),
    editor: mercury.value(null),
    frameList: mercury.value(frameList)
})

// When the data changes, save it
state.frames(frameData.save)

// Show the frame editor
frameList.onSelectFrame(function (frameId) {
    var editor = FrameEditor(state.frames[frameId])

    state.editor.set(editor)
    state.frameList.set(null)

    editor.onExit(function () {
        // Restore the frame list
        state.frameList.set(frameList)
        state.editor.set(null)
    })
})

function render(state) {
    // This is a mercury partial rendered with editor.state instead 
    // of globalSoup.state
    // The immutable internal event list is also passed in
    // Event listeners are obviously not serializable, but 
    // they can expose their state (listener set)
    return h(
        state.editor ? state.editor.partial() :
            state.frameList.partial()
    )
}

// setup the loop and go.
mercury.app(document.body, render, state)
{'fraction_non_alphanumeric': 0.11202185792349727, 'fraction_numerical': 0.0, 'mean_word_length': 3.358843537414966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7191384', 'n_tokens_mistral': 748, 'n_tokens_neox': 731, 'n_words': 224}