MCPcopy Create free account
hub / github.com/cryptii/cryptii / update

Method update

src/View/Pipe.js:133–192  ·  view source on GitHub ↗

* Integrates brick view elements inside pipe structure. * @return {PipeView} Fluent interface

()

Source from the content-addressed store, hash-verified

131 * @return {PipeView} Fluent interface
132 */
133 update () {
134 // Gather brick views in order
135 const bricks = this.getModel().getBricks()
136 const brickViews = bricks.map(brick => brick.getView())
137
138 this.getElement()
139 const $content = this._$content
140
141 // Detach each brick subview element without breaking it (emptying parent
142 // via innerHTML does not work in IE11)
143 brickViews.forEach(brickView => {
144 const $element = brickView.getElement()
145 $element.parentNode && $element.parentNode.removeChild($element)
146 })
147
148 // Empty content element
149 $content.innerHTML = ''
150
151 // Store reference and index for each pipe part
152 this._$pipeParts = []
153 this._pipePartIndex = []
154
155 // Compose pipe
156 let $pipePart
157 let cowards = []
158 for (let i = 0; i < bricks.length; i++) {
159 if (!bricks[i].isHidden()) {
160 // Append brick
161 $pipePart = this._createPipePart(i)
162 this._$pipeParts.push($pipePart)
163 this._pipePartIndex.push(i)
164
165 $content.appendChild($pipePart)
166 $content.appendChild(this._createBrickPart(brickViews[i]))
167 } else {
168 // Collect cowards
169 cowards.push(bricks[i])
170
171 // Append cowards group if this is the last coward in the group
172 if (i + 1 === bricks.length || !bricks[i + 1].isHidden()) {
173 const index = i - cowards.length + 1
174 $pipePart = this._createPipePart(index)
175 this._$pipeParts.push($pipePart)
176 this._pipePartIndex.push(index)
177 $content.appendChild($pipePart)
178 $content.appendChild(this._createCollapsedPart(cowards))
179 cowards = []
180 }
181 }
182 }
183
184 // Add end part
185 $pipePart = this._createPipePart(brickViews.length)
186 this._$pipeParts.push($pipePart)
187 this._pipePartIndex.push(brickViews.length)
188 $content.appendChild($pipePart)
189
190 this.layout()

Callers 4

appendSubviewElementMethod · 0.95
removeSubviewElementMethod · 0.95
createCipherMethod · 0.45
createDigestMethod · 0.45

Calls 9

_createPipePartMethod · 0.95
_createBrickPartMethod · 0.95
_createCollapsedPartMethod · 0.95
layoutMethod · 0.95
getBricksMethod · 0.80
getViewMethod · 0.80
getElementMethod · 0.80
isHiddenMethod · 0.80
getModelMethod · 0.45

Tested by

no test coverage detected