Giter Site home page Giter Site logo

Dynamic Properties about dashbook HOT 3 CLOSED

bluefireteam avatar bluefireteam commented on June 20, 2024
Dynamic Properties

from dashbook.

Comments (3)

erickzanardo avatar erickzanardo commented on June 20, 2024 2

Got it @jeffscaturro-aka, thanks for the further explanation, I made some adaptations to your suggestion and just submitted #49

from dashbook.

erickzanardo avatar erickzanardo commented on June 20, 2024

Hey, thanks for the suggestion.

I think I got the idea but I am not 100% sure.

Could elaborate more? Would be cool if you could put an example of what you would expect the API would look like.

from dashbook.

jeffscaturro-aka avatar jeffscaturro-aka commented on June 20, 2024

Sure!

We add options to the DashbookContext and store them in a map of properties: https://github.com/erickzanardo/dashbook/blob/f2581ce298242a07302482b4eccb8045197ce2a4/lib/src/story.dart#L26-L38

It would be valuable to add some logic conditional on another property's key/value pair. Here is some high-level pseudocode that I'm sure would bring in some edge-cases or handling that needs to be accounted for somewhere else, but it provides the gist of the ask here.

class DashbookContext {
  /// Contain the current BoxConstraints of the area available for the Chapter
  BoxConstraints? constraints;
  Map<String, Property> properties = {};

  String textProperty(
    String name,
    String defaultValue, {
    Map<String, dynamic>? removeWhen,
  }) {
    // FIXME: Would have to check all the key/value pairs.
    if (removeWhen != null &&
        properties[removeWhen.keys.first]?.getValue() ==
            removeWhen.values.first) {
      properties.remove(name);
      // FIXME: Verify what we'd want to return.
      return '';
    }

    if (properties.containsKey(name)) {
      return properties[name]!.getValue();
    } else {
      final property = Property<String>(name, defaultValue);
      properties[name] = property;

      return property.getValue();
    }
  }
...

This does work, but currently it doesn't until you rebuild the Properties tab.

This would then enable consumers to do something like:

...
text: dashbookContext.textProperty(
    'Error Text',
    'Oops, something went wrong!',
    removeWhen: {
        'state': 'success',
    },
  ),
...

Where the user would only see the "Error Text" property (on the Properties tab) if the Property who's key "state" and current value is not success. This would hide properties that may confuse or pollute the list of properties when not applicable.

I'm not saying this approach is the best way to accomplish this as I haven't looked too in-depth into the source code, but hopefully it provides more context and an example of the intent behind this ask.

Let me know if not.

from dashbook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.