Skip to content

Commit

Permalink
fix(core): Make editCond to work with all kinds (specific or abstract) (
Browse files Browse the repository at this point in the history
#132)

There is a bug in the implementation of editCond. Performance optimization introduced, have made usage of "patterns" for kinds to be stored in a Registry, making the usage to only return one transformation per kind.

By moving to MultivalueRegistry, we again are doing all registered transformations.
  • Loading branch information
andon committed Mar 12, 2019
1 parent 6abab00 commit 794a4b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/zip/__tests__/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Editing a Zipper', () => {
name: 'andon',
children: [
{
kind: 'tm',
kind: ['tm', 'yoga'],
name: 'blagoja',
},
{
Expand Down Expand Up @@ -60,6 +60,7 @@ describe('Editing a Zipper', () => {
item => item.get('name') === 'andon',
item => item.set('name', 'sikavica'),
],
[['tm', 'yoga'], item => item.update('name', name => `yoga-${name}`)],
['tm', item => item.update('name', name => `member-${name}`)],
],
elementZipper
Expand Down Expand Up @@ -90,8 +91,8 @@ describe('Editing a Zipper', () => {
name: 'sikavica', // changed
children: [
{
kind: 'tm',
name: 'member-blagoja', // changed
kind: ['tm', 'yoga'],
name: 'yoga-member-blagoja', // changed
},
{
kind: 'tm',
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/zip/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { postWalk } from '../zip'
import * as zip from './impl'
import { curry } from 'ramda'

import Registry from '../registry/Registry'
import MultivalueRegistry from '../registry/MultivalueRegistry'

export const editCond = (patterns, loc) => {
const kinds = new Registry()
const kinds = new MultivalueRegistry()
const preds = []

patterns.forEach(([pred, f]) => {
Expand All @@ -22,9 +22,7 @@ export const editCond = (patterns, loc) => {
const editFn = l =>
postWalk(el => {
const kind = kindOf(el)
const f = kind != null && kinds.get(kind)

if (f != null) el = f(el)
el = kinds.get(kind).reduce((el, f) => f(el), el)

const after = preds.reduce((el, [pred, f]) => (pred(el) ? f(el) : el), el)
return after
Expand Down

0 comments on commit 794a4b0

Please sign in to comment.