示例#1
0
文件: design.go 项目: influx6/gu
// newResource creates a new ResourceDefinition instance and adds the
// new resource into the root ResourceDefinition list.
func newResource(root *Resources, dsl DSL) *ResourceDefinition {
	var rs ResourceDefinition
	rs.Dsl = dsl
	rs.Order = Any
	rs.Root = root
	rs.uuid = gu.NewKey()
	rs.Manager = gu.NewRouteManager()
	rs.Resolver = dispatch.NewResolver("*")

	rsp := &rs
	root.Resources = append(root.Resources, rsp)

	dispatch.Subscribe(func(rv *ResourceViewUpdate) {

		if rv.Resource != rsp.uuid {
			return
		}

		if !rsp.active {
			return
		}

		rs.Root.renderer.RenderUpdate(rv.View, rv.Target, true)
	})

	return rsp
}
示例#2
0
文件: notifier.go 项目: influx6/gu
// starts begin listening for a SubmitNotification which gets displayed.
func (s *SubmissionNotifier) start() {
	dispatch.Subscribe(func(sme SubscriptionSubmitEvent) {
		s.c = sme
		s.Publish()
	})
}
示例#3
0
文件: design.go 项目: influx6/gu
// Init intializes all attached resources under its giving resource list.
func (rs *Resources) Init(useHashOnly ...bool) *Resources {
	var watchHash bool

	if len(useHashOnly) != 0 {
		watchHash = useHashOnly[0]
	}

	dispatch.Subscribe(func(pd dispatch.PathDirective) {
		if !watchHash {
			psx := dispatch.UseDirective(pd)
			if psx.String() == rs.lastPath.String() {
				return
			}

			rs.lastPath = psx

			if rs.renderer != nil {
				rs.renderer.Render(rs.Resolve(psx)...)
			}

			return
		}

		psx := dispatch.UseHashDirective(pd)
		if psx.String() == rs.lastPath.String() {
			return
		}

		rs.lastPath = psx

		if rs.renderer != nil {
			rs.renderer.Render(rs.Resolve(psx)...)
		}
	})

	var dslList []DSL

	collection.cl.Lock()
	{
		dslList = collection.collection
		collection.root = rs
		collection.collection = nil
	}
	collection.cl.Unlock()

	for _, dsl := range dslList {
		res := newResource(rs, dsl)
		res.Init()
	}

	collection.cl.Lock()
	{
		collection.root = nil
	}
	collection.cl.Unlock()

	if detect.IsBrowser() && rs.renderer != nil {
		du := rs.Resolve(dispatch.GetLocationHashAsPath())
		rs.renderer.Render(du...)
	}

	return rs
}