Skip to content

Compact Cursor Library built on top of the excellent seamless-immutable

License

Notifications You must be signed in to change notification settings

MartinSnyder/seamless-immutable-cursor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

seamless-immutable-cursor

Compact Cursor Library built on top of the excellent seamless-immutable. Cursors can be used to manage transitions and manipulations of immutable structures in an application.

Presentation

A 20 minute presentation explains the utility of this library and the repository contents. Slides can be viewed here

Example

const rootCursor = new Cursor({
    users: {
        abby: 1,
        ben: 2,
        claire: 3,
        dan: 4
    },
    documents: [
        {
            name: 'CV',
            owner: 1,
            mediaType: 'application/pdf'
        },
        {
            name: 'References',
            owner: 1,
            mediaType: 'text/plain'
        }
    ]
});

// Register a function to react to new generations of our immutable data
rootCursor.onChange((nextData, prevData, pathUpdated) => {
    console.debug('Updated ' + JSON.stringify(pathUpdated));
});

// Create a cursor for a limited portion of our data hierarchy
const childCursor = rootCursor.refine(['documents', 0, 'name']);

// firstDocumentName will be 'CV'
const firstDocumentName = childCursor.data;

// Update -- this switches the data owned by rootCursor to point to
// a new generation of immutable data
childCursor.data = 'Resume';

// updatedFirstDocumentName will be 'Resume' because the cursor points
// to the location, not the specific data
const updatedFirstDocumentName = childCursor.data;

// updatedFirstDocumentNameFromRoot will ALSO be 'Resume' because the
// 'managed' data has moved to a new generation based on the prior update
const updatedFirstDocumentNameFromRoot = rootCursor.data.documents[0].name;

React Demo

The demo folder contains a simple demo that combines this library, seamless-immutable and React.

About

Compact Cursor Library built on top of the excellent seamless-immutable

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published