Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 605e18c8 authored by Martin Stjernholm's avatar Martin Stjernholm Committed by android-build-merger
Browse files

Merge "Document how properties work in defaults modules." am: 188236ff

am: 3b2542d1

Change-Id: I4e81eeab8ad85cc686cdbeb124677070b45ad226
parents 3997da91 3b2542d1
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -63,9 +63,28 @@ func InitDefaultableModule(module DefaultableModule) {

type DefaultsModuleBase struct {
	DefaultableModuleBase
	defaultProperties []interface{}
}

// The common pattern for defaults modules is to register separate instances of
// the xxxProperties structs in the AddProperties calls, rather than reusing the
// ones inherited from Module.
//
// The effect is that e.g. myDefaultsModuleInstance.base().xxxProperties won't
// contain the values that have been set for the defaults module. Rather, to
// retrieve the values it is necessary to iterate over properties(). E.g. to get
// the commonProperties instance that have the real values:
//
//   d := myModule.(Defaults)
//   for _, props := range d.properties() {
//     if cp, ok := props.(*commonProperties); ok {
//       ... access property values in cp ...
//     }
//   }
//
// The rationale is that the properties on a defaults module apply to the
// defaultable modules using it, not to the defaults module itself. E.g. setting
// the "enabled" property false makes inheriting modules disabled by default,
// rather than disabling the defaults module itself.
type Defaults interface {
	Defaultable
	isDefaults() bool