import { VNode , VNodeData } from "../vnode" ; import { Module } from "./module" ; export type Classes = Record < string , boolean > ; function updateClass ( oldVnode , vnode ) { let cur ; let name ; const elm = vnode . elm as Element ; let oldClass = ( oldVnode . data as VNodeData ) . class ; let klass = ( vnode . data as VNodeData ) . class ; if ( ! oldClass && ! klass ) return ; if ( oldClass === klass ) return ; oldClass = oldClass || { } ; klass = klass || { } ; for ( name in oldClass ) { if ( oldClass [ name ] && ! Object . prototype . hasOwnProperty . call ( klass , name ) ) { elm . classList . remove ( name ) ; } } for ( name in klass ) { cur = klass [ name ] ; if ( cur !== oldClass [ name ] ) { ( elm . classList as any ) [ cur ? "add" : "remove" ] ( name ) ; } } } export const classModule = { create : updateClass , update : updateClass } ;