github.com/blend/go-sdk@v1.20240719.1/web/view_model.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package web 9 10 import ( 11 "github.com/blend/go-sdk/env" 12 ) 13 14 // ViewModel is a wrapping viewmodel. 15 type ViewModel struct { 16 Env env.Vars 17 Status ViewStatus 18 Ctx *Ctx 19 ViewModel interface{} 20 } 21 22 // Wrap returns a ViewModel that wraps a new object. 23 func (vm ViewModel) Wrap(other interface{}) ViewModel { 24 return ViewModel{ 25 Env: vm.Env, 26 Ctx: vm.Ctx, 27 ViewModel: other, 28 } 29 } 30 31 // State returns a state value. 32 func (vm ViewModel) State(key string) interface{} { 33 if vm.Ctx == nil || vm.Ctx.State == nil { 34 return nil 35 } 36 return vm.Ctx.State.Get(key) 37 }