(pivotSchema: IPublicTypeRootSchema, activities: any)
| 124 | * @deprecated |
| 125 | */ |
| 126 | export function applyActivities(pivotSchema: IPublicTypeRootSchema, activities: any): IPublicTypeRootSchema { |
| 127 | let schema = { ...pivotSchema }; |
| 128 | if (!Array.isArray(activities)) { |
| 129 | activities = [activities]; |
| 130 | } |
| 131 | return activities.reduce((accSchema: IPublicTypeRootSchema, activity: any) => { |
| 132 | if (activity.type === ActivityType.MODIFIED) { |
| 133 | const found = getNodeSchemaById(accSchema, activity.payload.schema.id); |
| 134 | if (!found) return accSchema; |
| 135 | Object.assign(found, activity.payload.schema); |
| 136 | } else if (activity.type === ActivityType.ADDED) { |
| 137 | const { payload } = activity; |
| 138 | const { location, schema } = payload; |
| 139 | const { parent } = location; |
| 140 | const found = getNodeSchemaById(accSchema, parent.nodeId); |
| 141 | if (found) { |
| 142 | if (Array.isArray(found.children)) { |
| 143 | found.children.splice(parent.index, 0, schema); |
| 144 | } else if (!found.children) { |
| 145 | found.children = [schema]; |
| 146 | } |
| 147 | // TODO: 是 JSExpression / DOMText |
| 148 | } |
| 149 | } else if (activity.type === ActivityType.DELETED) { |
| 150 | const { payload } = activity; |
| 151 | const { location } = payload; |
| 152 | const { parent } = location; |
| 153 | const found = getNodeSchemaById(accSchema, parent.nodeId); |
| 154 | if (found && Array.isArray(found.children)) { |
| 155 | found.children.splice(parent.index, 1); |
| 156 | } |
| 157 | } |
| 158 | return accSchema; |
| 159 | }, schema); |
| 160 | } |
no test coverage detected
searching dependent graphs…