コード例 #1
0
ファイル: diff.go プロジェクト: codefarms/drops
//test to see if elements of children are equal for every element
func testChildrenEquality(view1 *element.View, view2 *element.View) ([]Patch, bool) {
	patches := make([]Patch, 0)
	cont := true //continue
	biggerChildren := len(view1.Children)
	if view2.Children != nil && len(view2.Children) > biggerChildren {
		biggerChildren = len(view2.Children)
	}
	for i := 0; i < biggerChildren; i++ {
		var v1 *element.View
		var v2 *element.View
		if i < len(view1.Children) {
			v1 = view1.Children[i]
		}
		if i < len(view2.Children) {
			v2 = view2.Children[i]
		}
		// fmt.Printf("Model 1 %+v \n", v1.Model)
		// fmt.Printf("Model 2 %+v \n", v2.Model)

		modelEqual := reflect.DeepEqual(v1.Model, v2.Model)
		if !modelEqual {
			buff := element.Render(v2)
			patchElement := v2.InjectInto

			patch := &Patch{Element: patchElement, Payload: buff.String()}
			patches = append(patches, *patch)

			cont = false
		} else {
			patches = append(patches, Diff(v1, v2)...)
		}
	}
	return patches, cont
}
コード例 #2
0
ファイル: diff.go プロジェクト: codefarms/drops
//test to see if views are equal
func testEquality(view1 *element.View, view2 *element.View) ([]Patch, bool) {
	patches := make([]Patch, 0)
	cont := true //continue
	same := true
	if view1 != nil && view2 != nil {
		same = true
	}
	same = reflect.DeepEqual(view1.Model, view2.Model)

	if same && view1.Template != view2.Template {
		same = false
	}
	if !same {
		buff := element.Render(view2)
		patchElement := view2.Provides

		patch := &Patch{Element: patchElement, Payload: buff.String()}
		patches = append(patches, *patch)
		// fmt.Printf("\nview1: %+v\n", view1)
		// fmt.Printf("\nview2: %+v\n", view2)
		// fmt.Printf("\nequal: %+v\n", view1.Model == view2.Model)

		cont = false
	}
	if len(patches) > 0 {
		// fmt.Println("\nGenerated patches on testEquality")
	}
	return patches, cont
}
コード例 #3
0
ファイル: diff.go プロジェクト: codefarms/drops
//Rules
//test for length of children, if length different, generate patch
func testLength(view1 *element.View, view2 *element.View) ([]Patch, bool) {
	patches := make([]Patch, 0)
	cont := true //continue
	if len(view1.Children) != len(view2.Children) {
		buff := element.Render(view2)
		patchElement := view2.Provides

		patch := &Patch{Element: patchElement, Payload: buff.String()}
		patches = append(patches, *patch)
		cont = false
	}
	if len(patches) > 0 {
		// fmt.Println("\nGenerated patches on testLength")
	}
	return patches, cont
}
コード例 #4
0
ファイル: drops.go プロジェクト: codefarms/drops
func ResourceHandler(w http.ResponseWriter, r *http.Request, dropsResponse *protocol.DropsResponse) *protocol.DropsResponse {
	// log.Printf("Resource handler: %s - %s\n", r.Method, r.URL.Path)
	var response string

	if w != nil && dropsResponse.Dom != nil {
		var sessionId string
		sessionCookie, err := r.Cookie("session")
		// fmt.Printf("sessionCookie: %+v\n", pretty.Formatter(sessionCookie))
		if err != nil {
			// fmt.Printf("Error fetching cookie %v\n", err)
			//No cookie found
			sessionId = session.CreateSession("")
			sessionCookie = &http.Cookie{Name: "session", Value: sessionId, Path: "/"}
			// fmt.Printf("Created Cookie: %s: %+v\n", sessionCookie.Name, sessionCookie.Value)
		} else {
			// log.Printf("Cookie: %s: %+v\n", sessionCookie.Name, sessionCookie.Value)
			sessionId = sessionCookie.Value
			if !session.SessionExist(sessionId) {
				sessionId = session.CreateSession(sessionId)
			}
			sessionCookie = &http.Cookie{Name: "session", Value: sessionId, Path: "/"}
			// sessionCookie.Value = sessionId
		}
		// fmt.Printf("sessionId: %s\n", sessionId)
		session.SetSessionActiveDOM(sessionId, dropsResponse.Dom)
		// fmt.Printf("\ndom set as active: %+v\n", pretty.Formatter(dom.Id))

		// ActiveDOM = dom
		buffer := element.Render(&dropsResponse.Dom.View)
		response = buffer.String()
		// cookie := &http.Cookie{Name: "session", Value: sessionId}
		// http.Set
		http.SetCookie(w, sessionCookie)

		fmt.Fprint(w, response)

		return nil
	}
	return dropsResponse
}