 	let fileId: Int
 	var codeHandler: PreviewCodeHandler
 	var lastAccess: TimeInterval = Date.timeIntervalSinceReferenceDate
+	var updateObserver: Signal<Void, Rc2Error>.Observer?
 }
 
 // MARK: - SessionPreviewDelegate
 extension LivePreviewDisplayController: SessionPreviewDelegate {
 	func previewIdReceived(response: SessionResponse.PreviewInitedData) {
-
+		// do nothing because signal value triggers setting it
+		Log.info("got preview Id \(response.previewId)")
 	}
 
 	func previewUpdateReceived(response: SessionResponse.PreviewUpdateData) {
-		// TODO: need to update codeHandler's chunk cache, update display of that chunk
+		guard let doc = parsedDocument else {
+			Log.warn("preview update witout a document", .app)
+			return
+		}
+		guard var preview = previewData[response.previewId] else { return }
+		var toCache = [response.chunkId]
+		preview.codeHandler.cacheCode(changedChunks: &toCache, in: doc)
+		let html = preview.codeHandler.htmlForChunk(document: doc, number: response.chunkId)
+		preview.lastAccess = Date.timeIntervalSinceReferenceDate
+		let script = """
+		$("sectionContent[index=\(response.chunkId)]").innerHtml = \(html)")
+		"""
+		runJavascript(script)
 	}
 }

		}
	}

	// MARK: - utility

	func setEditorContext(_ econtext: EditorContext?) {
		precondition(context.value == nil)
		context.value = econtext
	}

	private func requestPreviewId(fileId: Int) -> SignalProducer<PreviewIdCache, Rc2Error> {
		let handler = SignalProducer<PreviewIdCache, Rc2Error> { observer, _ in
			return self.session.requestPreviewId(fileId: fileId).startWithResult { (result) in
				switch result {
				case .success(let previewId):
					Log.info("got previewId \(previewId)")
					let codeHandler = PreviewCodeHandler(previewId: previewId)
					let cacheEntry = PreviewIdCache(previewId: previewId, fileId: fileId, codeHandler: codeHandler)
					observer.send(value: cacheEntry)
				case .failure(let err):
					Log.warn("requestPreviewId got error \(err)")
					observer.send(error: err)

	private let mdownParser = MarkdownParser()
	private var previewData = [Int: PreviewIdCache]()
	private var currentPreview: PreviewIdCache?
	private var initialCodeLoaded = false
	private var previewRequestInProgress: Bool = false

	// regular expressions
	private var lineContiuationRegex: NSRegularExpression!
