Child pages
  • fluid.model.transformWithRules

This documentation is currently being moved to our new documentation site.

Please view or edit the documentation there, instead.

If you're looking for Fluid Project coordination, design, communication, etc, try the Fluid Project Wiki.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

This functionality is Sneak Peek status. This means that the APIs may change. We welcome your feedback, ideas, and code, but please use caution if you use this new functionality.

This page is still a rough draft.

Unknown macro: {div}

fluid.model.transformWithRules(model, rules)

Transforms a model based on a specified expansion rules objects.

fluid.model.transformWithRules(model, rules);

File name: ModelTransformation.js

Parameters

Unknown macro: {span}

model

(Object) the model to transform

rules

(Object) a rules object containing instructions on how to transform the model (see below for more information)

Return Value

Unknown macro: {span}

Object

the transformed model


Rules

Rules objects take the form of:

{
    "target.path": "value.el.path" || {
        expander: {
            type: "expander.function.path",
             ...
        }
    }
}

Transformation Expanders

The Framework currently provides the following expanders that can be used as part of a model transformation.

fluid.model.transform.value

This extracts and/or the value of a given path, and can be used for the following purposes:

To rename a property

Start:

var source = {
    cat: "meow",
    ...
}



>>

Rule to rename "cat" to "feline":

var rules = {
    feline: { 
        expander: {
            type: "fluid.model.transform.value",
            // specify only a new path
            path: "cat"
        }
    },
    ....
}



>>

Result:

{
    feline: "meow",
    ...
}

To set a default value:

Start:

var source = {
    gerbil: undefined,
    // or if "gerbil" doesn't exist
    ...
}



>>

Rule to set default value of "gerbil":

var rules = {
    gerbil: { 
        expander: {
            type: "fluid.model.transform.value",
            // specify the path and the default value
            path: "gerbil",
            value: "squeek"
        }
    },
    ....
}



>>

Result:

{
    gerbil: "squeek",
    ...
}

Note that if "gerbil" has a value initially, it will be unaffected.

To specify a literal value:

Start:

var source = {
    // no mention of kangaroos
    ...
}



>>

Rule to set default value of "gerbil":

var rules = {
    gerbil: { 
        kangaroo: {
            type: "fluid.model.transform.value",
            // specify only a value
            value: "boingg"
        }
    },
    ....
}



>>

Result:

{
    kangaroo: "boingg",
    ...
}

To change the structure/nesting:

Start:

var source = {
    goat: false,
    sheep: [
        "baaa",
        "wooooool"
    ],
    ...
}



>>

Rule to set default value of "gerbil":

var rules = {
    "farm.goat": {                                          
        expander: {
            type: "fluid.model.transform.value",
            path: "goat"
        }
    },
    "farm.sheep": {
        expander: {
            type: "fluid.model.transform.value",
            path: "sheep"
        }
    } 
    ....
}



>>

Result:

{
    farm: {
        goat: false,
        sheep: [
            "baaa",
            "wooooool"
        ]
    },
    ...
}

fluid.model.transform.arrayValue

fluid.model.transform.firstValue

fluid.model.transform.merge

Example


In this example, description here...

  • No labels